Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Photographer menu/submenu

Started by tony 8 years ago · 4 replies · 779 views
8 years ago

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?

8 years ago

@antoine0579

The macro loop

Looking at navigation.html.twig...

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'

YAML
dropdown:
  enabled: false

If 'dropdown.enabled' is 'true', the macro is called and pages can have dropdown menus. E.g.

TXT
/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:

TWIG
{% 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.

TWIG
{{ dump('macro called') }}
{{ dump(config.themes.photographer.dropdown.enabled) }}

These dumps can easily be inspected by enabling the debugger in '/user/config/system.yaml':

YAML
debugger:
  enabled: true
last edited 07/22/18 by pamtbaau
8 years ago

Thank you for your feedback. However I found it much easier to use the quark theme for dropdown menu than using tintamarre

8 years ago

@antoine0579 I'm afraid I do not quite understand what you mean by "easier to work with"?

Tintamarre? Did your mean Photographer?

8 years ago

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.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 99 16 hours ago
General · by pamtbaau, 21 hours ago
1 63 21 hours ago
General · by Andy Miller, 1 day ago
0 48 1 day ago
General · by Marcel, 12 months ago
6 357 5 days ago
General · by Duc , 6 days ago
3 45 6 days ago