I have a layout in the current version of Middleman (3.0.14). I would like to pulling page specific stylesheets or script if they exist.
In the layout I currently have:
<%= stylesheet_link_tag "global", data.page.stylesheet %>
and in the YAML front matter I have:
stylesheet: homepage
The issue I'm having is that I would like to have the CSS render only if there is a stylesheet tag in the YAML from matter. Currently what happens is if there is no stylesheet tag in the YAML front matter it just renders a blank .css file.
Thanks in advance for any assistance.
Does ...
<%= stylesheet_link_tag "global", (data.page.stylesheet ? data.page.stylesheet : {}) %>
... do the trick for you? As the 'stylesheet' key might be not set correctly within the Front Matter (stylesheet:
or stylesheet: ""
) you could even do some more checks:
<%= stylesheet_link_tag "global", ((data.page.has_key?('stylesheet') && ! data.page.stylesheet.nil? && ! data.page.stylesheet.empty?) ? data.page.stylesheet : {}) %>