Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referencing `current_page.data.layout` in an IF Statement #1965

Closed
folo1988 opened this issue Jul 25, 2016 · 5 comments

Comments

@folo1988
Copy link

commented Jul 25, 2016

Trying to reference the layout of the current page does not work:

<%
  if current_page.data.layout == "alt_layout"
    @var = "x"
  elsif
    @var = "y"
  end
  %>

However, trying to do the same on a separate item of frontmatter does:

<%
  if current_page.data.x == "alt_layout"
    @var = "x"
  elsif
    @var = "y"
  end
  %>

Example YAML:


---
layout: alt_layout
x: alt_layout

---
@tdreyno

This comment has been minimized.

Copy link
Member

commented Oct 8, 2016

If you print current_page.data.x, what is the value?

@folo1988

This comment has been minimized.

Copy link
Author

commented Oct 13, 2016

Sorry for the late reply.

It is indeed 'alt_layout' when I do <%= current_page.data.x %>.

I'm still a bit of a Ruby newb, is 'layout' something special? if I write <%= current_page.data.layout %> 'layout' gets the same syntax highlighting that 'gsub' does (I must have missed that when I first filed the issue).

@hello-jason

This comment has been minimized.

Copy link

commented Apr 21, 2017

I'm also experiencing this issue.

Trying the following does not work:

- unless current_page.data.layout == "my-layout"
  // does not work

However checking another frontmatter variable does work:

- unless current_page.data.body_class == "my-body-class"
  // works

For context, using middleman 4.2.1 and slim 3.0.7

@adamhollett

This comment has been minimized.

Copy link

commented Apr 22, 2017

You may be able to use current_page.options[:layout] -- from my experience layout is considered an option and not metadata.

@hello-jason

This comment has been minimized.

Copy link

commented Apr 22, 2017

This is the fix: current_page.options[:layout]. Thanks @admhlt

@iwarner iwarner closed this May 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.