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

Twig if else using page as condition

Started by Muut Archive 9 years ago · 2 replies · 2730 views
9 years ago

Hi there,

I'm trying to edit the base.html.twig so that the home page shows a certain logo and all other pages show another. I tried using an if else statement, but am not sure how to call a page within the statement....have tried for example:

TWIG
 {% if title == home %}
 <h3><a href="{{ base_url == '' ? '/' : base_url }}"><img src="{{ url('theme://images/logowhite.png') }}" /></a></h3>
{% else %}
<h3><a href="{{ base_url == '' ? '/' : base_url }}"><img src="{{ url('theme://images/logo.png') }}" /></a></h3>
{% endif %}

but end up with the same logo (logowhite) on all pages, not only the homepage.

Any pointers will be really appreciated :=)

9 years ago

I wanted to do something similar but with content for the home page only which I did something like this

TWIG
    logo code
{% else %}
   blah blah
{% endif %}

Another way might be to filter on the template type if your homepage happens to have a specific one e.g.

TWIG
            logo code
{% else %}
{% endif %}

Also the using the dump command along with the grav debugger will tell you what "title" is actually outputting.

TXT

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1333 9 years ago
Archive · by Muut Archive, 9 years ago
2 924 9 years ago
Archive · by Muut Archive, 9 years ago
2 4055 9 years ago
Archive · by Muut Archive, 9 years ago
1 2938 9 years ago
Archive · by Muut Archive, 9 years ago
3 1111 9 years ago