Change sidebar contains for specific parts on site

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

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 :slight_smile:

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’.

Not really dynamic. Just fixed content.

How can i make this taxonomies for certain pages?

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

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!

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

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

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

Sure :slight_smile: