Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow identification of top-level menu item (in the case of nested children) #24

Open
ybressler opened this issue Apr 15, 2022 · 1 comment

Comments

@ybressler
Copy link

Say I have a menu whose structure looks as follows:

menu:
  - home
  - about us
  - api documentation
    children:
    - getting started
    - advanced guide

When looping through my menu items, I want to identify if an element is top level or not – in this case: ["home", "about us", "api documentation"].

Here's what that would look like in _includes/menus.html:

{% if menu %}
  <ul>
  {% for item in menu %}
    <li class="menu-item-{{ loop.index }}">

        {% if item.is_root_level %}
            {{ DO SOMETHING SPECIAL HERE }}
        {% endif %}

      <a href="{{ item.url }}" title="Go to {{ item.title }}"> {{ item.title }} </a>
      {% if item.children %}
        {% assign menu = item.children %}
        {% include menu.html %}
      {% endif %}
    </li>
  {% endfor %}
  </ul>
{% endif %}

I imagine I can traverse the item.parent attribute, but am not sure what the best way to go about this would be. Would appreciate any support you can provide.

@ybressler
Copy link
Author

Note, this issue is downstream from this bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant