Passing a variable to a template in Middleman 2

I have a Middleman project and I need to emulate a registered user.

Simple enough - it would be nice to set some global variable, for example @user = 1 in config.rb, the code for the user logged in, then set the variable to 0 and encode everything for the user displayed by the user, if everywhere

I am not a Ruby encoder, so I do not understand where to connect. So: how to set the global application variable in middleman config.rb?

+6
source share
1 answer

You can set the variable on specific paths using the page helper:

 page "/my-page.html", :locals => { :is_logged_in => true } 

If you want to use a single template that includes an if to handle changes to content based on is_logged_in , you should use page proxies:

 page "/my-page-logged-in.html", :proxy => "/my-page.html", :locals => { :is_logged_in => true } page "/my-page-logged-out.html", :proxy => "/my-page.html", :locals => { :is_logged_in => false } 

For direct variables, use set :

 set :is_logged_in, true 

In the template:

 <%= is_logged_in %> 
+12
source

Source: https://habr.com/ru/post/911602/


All Articles