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

Change sidebar contains for specific parts on site

Started by Muut Archive 10 years ago · 7 replies · 575 views
10 years ago

Hi all,

I really like Grav. It's a cute and complete cms.

I want to have a sidebar which changes on specific parts on the site.

So on part a (i want the sidebar to be abc) and on part b (i want the sidebar to be xyz)

I found the sidebar twig but i am having some issues with showing the right content at the right time.

I think twig should look at the url if it contains a specific keyword is should show content (or not)

Example urls:
http://blog.duinmayer.nl/blogs
http://blog.duinmayer.nl/persoonlijke-blogs

10 years ago

So when someone opens blog.duinmayer.nl/persoonlijke-blogs i want them to see another sidebar then the one on blog.duinmayer.nl/blogs

So two or more urls with their own specific sidebar content :)

10 years ago

Depending on exactly how dynamic this sidebar should be you could include taxonomies for certain pages. Then use twig to check the page's taxonomy and based on that either display 'abc' or 'xyz'.

10 years ago

Not really dynamic. Just fixed content.

How can i make this taxonomies for certain pages?

10 years ago

just create a new taxonomy in the admin panel, or directly into the site.yaml file (see your config folder).

let's assume you create a taxonomy called 'sidebar'

then add the following to the frontmatter yaml of the page you wish to include

YAML
taxonomy:
    sidebar:
        - 'yes'

then you should be able to call it through a twig expression:

{% if page in taxonomy.findTaxonomy({'shortcut':'yes'}) %}
// do this
{% else %}
// do this
{% endif %}

Im not 100% sure about the above twig expression but I can't test it out for you right now. The idea above should work, im just not sure if the expression is completely correct.. maybe someone else can confirm if the above would be the correct way or try fiddle around with it a bit!

10 years ago

Use the page frontmatter to set a sidebar_type variable and use it in your template like this:

TWIG
     // unique sidebar content
{% elseif sidebar.type == "list" %}
    // unique sidebar content
{% else %}
     // default sidebar content
{% endif %}
// Always on sidebar content
10 years ago

@ryan they are both the same type :) Can i do something like page.header.sidebar_name == "something" ?

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1352 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4064 9 years ago
Archive · by Muut Archive, 9 years ago
1 2949 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago