Good evening:
I am studying the photographer skeleton and more specifically the menu template.
To analyze it I commented out the top section, ie the macro loop.
Lo and behold, it did not make any difference in the menu behavior. therefore I would like to know the purpose of that macro because it seems to do nothing.
Also I would like to debug the menu template by displaying variables inside this template.
Unfortunately, twig has no break/continue function. So what am I to do?
The macro loop
Looking at navigation.html.twig…
<ul class="nav sf-menu">
{% if config.themes.photographer.dropdown.enabled %}
{{ _self.loop(pages) }}
… we see that the macro ‘loop’ is only called when the theme variable ‘dropdown.enabled’ is set to ‘true’ in ‘/user/themes/photographer/photographer.yaml’ (or even better in ‘/user/config/themes/photographer.yaml’). The default value is ‘false’
dropdown:
enabled: false
If ‘dropdown.enabled’ is ‘true’, the macro is called and pages can have dropdown menus. E.g.
/user/pages/
01.home/
02.about/
01.about-you/
about.md
about.md
page2_img1.jpg
03.gallery/
...
Menuitem ‘about me’ will now show a dropdown menu like ‘submenu’ has.
Unfortunately, when enabling dropdown, ‘home’ will get and empty submenu. This can be fixed by replacing {% if p.children.count > 0 %}
on line 9, by:
{% if p.children.visible.count > 0 %}
Note: The last menuitem ‘submenu’ are no pages and are generated in the {% for mitem in site.menu %}
loop using ‘site.yaml’
Debugging Twig
I’m not aware of the possibility of step-by-step debugging of Twig. What you can do is ‘dump’-ing variables or strings/numbers. See Debugging & Logging.
{{ dump('macro called') }}
{{ dump(config.themes.photographer.dropdown.enabled) }}
These dumps can easily be inspected by enabling the debugger in ‘/user/config/system.yaml’:
debugger:
enabled: true
Thank you for your feedback. However I found it much easier to use the quark theme for dropdown menu than using tintamarre
@antoine0579 I’m afraid I do not quite understand what you mean by “easier to work with”?
Tintamarre? Did your mean Photographer?
Hello: what I meant was that I was able to create a dropdown menu using quark theme but I was unable to do it using tintamarre.