0

What is the best way to hide e.g. a nav bar on certain pages in Timber Twig templates. Have tried wrapping the navbar element in

{% if post.title !== 'foo bar' %}
// show the nav
{% endif %}

But that doesn't work.

larpo
  • 1,073
  • 1
  • 10
  • 18

1 Answers1

1

You can't use !== in twig. You have to use !=

Working snippet: https://twigfiddle.com/9l9lrc

{% set var = 'foo bar' %}
{% if var != 'foo bar' %}
    <h2>Nav</h2>
{% else %}
    <em>no-nav</em>
{% endif %}
goto
  • 7,908
  • 10
  • 48
  • 58
  • Thanks. Out of interest, is there a way to something like {% if var does does not contain 'string' %}? – larpo Feb 21 '17 at 15:57
  • 1
    yes: http://stackoverflow.com/questions/13007288/find-substring-in-the-string-in-twig – goto Feb 21 '17 at 16:00