Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

If statement based on frontmatter

Started by Muut Archive 9 years ago · 1 replies · 434 views
9 years ago

I have added an extra input in the page blueprint so the user can choose what look she wants the blogpost to have. Now I would like to do an if statement based on this user input. I tried it like this:

TWIG
{% if (page.header.look) == 'Shadow-left' %}
   some HTML
{% else %}
  other HTML
{% endif %}

I guess I'm doing something wrong. Can anyone help me out? Thanks!

9 years ago

Don't wrap the page.header.look with parens. It should be:

TWIG
{% if page.header.look == 'Shadow-left' %}
   some HTML
{% else %}
  other HTML
{% endif %}

The other way you could do it is make it a boolean instead of a string:

TWIG
{% if page.header.shadowLeft == true %}
   some HTML
{% else %}
  other HTML
{% endif %}

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1349 9 years ago
Archive · by Muut Archive, 9 years ago
2 934 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2946 9 years ago
Archive · by Muut Archive, 9 years ago
3 1117 9 years ago