0

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'?

user1419762
  • 3,571
  • 5
  • 20
  • 10
  • 2
    I'm not sure about middleman specifically, but I'm going to hazard an educated guess that `page_classes` is nit a variable, but is actually a method. – d11wtq May 27 '12 at 04:39

3 Answers3

3

<%= 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.

  • for /index.html it returns index
  • for /folder1/index.html it returns folder1 folder1_index
  • for /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.

fk_
  • 1,426
  • 12
  • 20
1

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.

Marek Maurizio
  • 1,073
  • 2
  • 11
  • 22
0

You can define variable in config.rb

set :var, ["something", "here"]

In your template you will have available

config[:var]
TWONEKSONE
  • 3,918
  • 3
  • 19
  • 26