picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.82k stars 616 forks source link

Looking for dropdown menu examples #487

Closed jtc242 closed 5 years ago

jtc242 commented 5 years ago

I am not a coder but can cobble together pieces of code to generally do what I want. I am looking for example sites and/or code using pico and drop down menus. I need samples plus the location of the files I need to edit. I have top navigation with upwards of 10 sub pages I want shown in a drop down style. Any help/pointers are appreciated.

CodeTipsy commented 5 years ago

You see http://picocms.org/cookbook/

PhrozenByte commented 5 years ago

The best way to create a recursive page menu is Pico's page tree feature. You can add the following Twig snippet to your themes/my_theme/index.twig:

{% macro tree(parent) %}
    {% import _self as utils %}
    {% for child in parent.children %}
        <li>
            {% if child.page %}
                <div>{{ child.page.title }}</div>
            {% endif %}
            {% if child.children %}
                <ul>
                    {{ utils.tree(child) }}
                </ul>
            {% endif %}
        </li>
    {% endfor %}
{% endmacro %}

<ul>
    <li>
        <div>{{ pages["index"].title }}</div>
    </li>

    {% import _self as utils %}
    {{ utils.tree(pages["index"].tree_node) }}
</ul>
stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1: