bolt / bolt/docs

Bolt theme templating, set menu active from record template

Open
#155 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
45
Forks
189
PR merge metrics
No merged PRs in 30d

Description

A work-around to set a menu item to active,
pass an `activepage` variable to the macro.

When on a record-template for a contenttype,
before including header.twig, you set activepage
`{% set activepage = 'menulabel' %}`
This will seep thru to the menu macro, and checks for
`{% if item|current or activemenu|lower == item.label|lower %} active{% endif %}`

``` twig
{# -------------------------------------------------- #}
{# record_template: events_detail.twig #}

{% set activepage = 'bijeenkomsten' %}
{% include '_header.twig' with {'activepage':activepage} %}
...
{# -------------------------------------------------- #}
{# _header.twig #}
...
{{ menu('main', '_sub_menu.twig', {'activemenu':(activepage is defined ? activepage : '')}) }}
...
{# -------------------------------------------------- #}
{# _sub_menu.twig #}

{% macro display_menu_item(item, loop, activemenu) %}
{% from _self import display_menu_item %}



  • {{item.label}}

    {% if item.submenu is defined %}

    {% endif %}

  • {% endmacro %}

    {% from _self import display_menu_item %}

    {% for item in menu %}
    {% if item.label is defined %}
    {{ display_menu_item(item, loop, activemenu) }}
    {% endif %}
    {% endfor %}
    ```

    Contributor guide

    No contributing guide indexed for this repository

    Assessment

    This issue has not been assessed yet.

    Get new issues in your inbox

    A short digest of beginner-friendly GitHub issues.