We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Macros vs Include recursive: Create Menu

I create a tree menu with:

<!--includes/menu-links.html-->
{% for link in links %}
    <li>
        <a href="{{ link.href }}">{{ link.name }}</a>
        {% if link.sublinks %}
            <ul>
                {% include "includes/menu-links.html" with ['links': link.sublinks] %}
            </ul>
        {% endif %}
    </li>
{% endfor %}

call:

<ul class="main-menu">
    {% include "includes/menu-links.html" with ['links':links] %}
</ul>

or

<!--macros/menu-macros.html-->
{% macro menu_links(links) %}
    {% for link in links %}
        <li>
            <a href="{{ link.href }}">{{ link.name }}</a>
            {% if link.sublinks %}
                <ul>
                    {{ menu_links(link.sublinks) }}
                </ul>
            {% endif %}
        </li>
    {% endfor %}
{% endmacro %}

call:

<ul class="main-menu">
    {{ macros.menu_links(links) }}
</ul>

What approach would have a better performance?



85.5k

you can test it yourself https://stackoverflow.com/questions/535020/tracking-the-script-execution-time-in-php

anyways i doubt there will be any difference.

Please post the results afterwards