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

Display different widget based on current page

Started by Muut Archive 10 years ago · 2 replies · 333 views
10 years ago

Is there a way to display a different aspect of a page based on the URL?

So for example, on the homepage, I will have a widget that will activate a filtering action on the work. I, of course, don't want that on any of the other pages. So in my base twig file, I was conceptually thinking of setting up an if else situation. The tricky part is each page has their own widget. So on the contact page, I'll have a social media widget and on each of the work detail pages I'll have taxonomies of the project and tools used in the project.

So in theory, (not proper syntax, just thinking out loud.):

{% if page.url == ('/') %}
include statement_display widget
{% ifelse page.url == ('/work-detail/') %}
include statement_display widget
{% ifelse page.url == ('/about') %}
include statement_display widget
{% ifelse page.url == ('/'contact') %}
include statement_display widget
{% endif %}

I have tried many ways that i can think of to accomplish this, not working. Any advice on how to implement this?

10 years ago

There are many ways but for these more complex situations, gantry framework is going to be your best friend: http://gantry.org

This is coming to Grav soon...

10 years ago

Looking forward to try gantry with grav!
As for your conditional display, your reasoning seems right.
Did you try

TWIG
{% if page.active == page.find(/about) %}
{% include ______.html.twig %}
{% endif %}

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1366 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1124 9 years ago