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

Creating nested submenu #383

Closed
sajidmc opened this issue Apr 20, 2017 · 1 comment
Closed

Creating nested submenu #383

sajidmc opened this issue Apr 20, 2017 · 1 comment

Comments

@sajidmc
Copy link

sajidmc commented Apr 20, 2017

Hi,

I was trying to create a web page with Pico. In the menu, is it possible to have only the root level pages, and each subpage as a submenu of each root pages ?

Directory structure:
index.md
about\index.md
about\mypeople.md
pictures\index.md
pictures\2016.md
pictures\2015.md
contact.md

Menu items:
Home
About
- My People
Pictures
- 2016
- 2015
Contact

@PhrozenByte
Copy link
Collaborator

I've answered this question in #picocms on Freenode. Just for the record, this is the final solution @sajidmc was asking for:

<ul>
    {% for page in pages if page.title %}
        {% if parentPage and not (page.id starts with parentPage) %}
            {% set parentPage = null %}
                </ul>
            </li>
        {% endif %}

        {% set pageDepth = page.id|split('/')|length %}
        {% if pageDepth == 1 %}
            <li><a href="{{ page.url }}">{{ page.title }}</a></li>
        {% elseif (pageDepth == 2) and (page.id ends with "/index") %}
            {% set parentPage = page.id|slice(0, -5) %}
            <li>
                <a href="{{ page.url }}">{{ page.title }}</a>
                <ul>
        {% elseif (pageDepth == 2) and parentPage %}
            <li><a href="{{ page.url }}">{{ page.title }}</a></li>
        {% endif %}
    {% endfor %}
</ul>

{% if parentPage %}
    {% set parentPage = null %}
        </ul>
    </li>
{% endif %}

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

No branches or pull requests

2 participants