I have a Middleman project and I need to emulate a logged-in user.
Simple enough - would be fine to set some global variable like @user = 1 in config.rb, code everything for the logged-in user, then set the variable to 0 and code everything for the logged-out user putting if's everywhere
I'm not a Ruby coder so I don't understand where to hook in. So: how can I set a global app variable in a middleman's config.rb?
You can set variable on specific paths using the page
helper:
page "/my-page.html", :locals => { :is_logged_in => true }
If you wanted to use a single template, which include an if
statement to handle content changes based on is_logged_in
, you would use a page proxy:
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 template:
<%= is_logged_in %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With