In the layout
file of haml
I would like to determine whether we are in our development and build environments. We're using Middleman.
I would like to do something like this:
- if environment == 'development'
/ Development Code
= javascript_include_tag "Dev.js"
I tried to access Ruby's environment variable, as well as define a custom variable in the config.rb
file with no success.
You’ve almost got it right – you need to check against a symbol rather than a string:
- if environment == :development
/ Development Code
= javascript_include_tag "Dev.js"
Middleman also adds the development?
and build?
methods which may be easier to use:
- if development?
/ Development Code
= javascript_include_tag "Dev.js"
This works with ERB too:
<% if development? %>
<!-- Development Code -->
<%= javascript_include_tag "Dev.js" %>
<% end %>
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