I've started experimenting with middleman and ruby.
The sample layout has this string:
<body class="<%= page_classes %>
On any given page, how do I set the 'page_class'?
I've started experimenting with middleman and ruby.
The sample layout has this string:
<body class="<%= page_classes %>
On any given page, how do I set the 'page_class'?
<%= page_classes %>
is one of Middleman's default view helpers and returns a string based upon the current page's filename and directory, e. g.
/index.html
it returns index
/folder1/index.html
it returns folder1 folder1_index
/folder1/folder2/page.html
it returns folder1 folder1_folder2 folder1_folder2_page
and so on (above examples are adapted from Middleman's Relish documentation for 'page_classes').
Using the snippet from the sample layout like you posted, you could style your pages or highlight the corresponding navigation item via CSS.
Edit: To add even more options to the answers provided by Marek, you could use
both of which are described on Middleman's website/documentation.
Note that variables set via YAML Frontmatter also become available in your layouts.
You can define variable in config.rb with the @ symbol such as:
@var = ["something", "here", ...]
and make it visible to templates by adding, in config.rb:
set :var, @var
if it's a method instead, you should just define it under the helper section of config.rb.
You can define variable in config.rb
set :var, ["something", "here"]
In your template you will have available
config[:var]