I try to make my first site with GRAV CMS.
Now in my pages-folder it looks like this:
home/default.md
about
about/seite1/default.md
about/seite2/default.md
Now, if i put the following code into my html-file, only the main points are showed in the navigation.
<nav class="" role="navigation">
<div class="">
<ol class="">
{% for page in pages.children %}
{% if page.visible %}
{% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
<li class="{{ current_page }}"><a href="{{ page.url }}">{{ page.menu }}</a</li>
{% endif %}
{% endfor %}
</ol>
</div>
</nav>
Is there a way to show all the pages, including subpages in the navigation?
thanks for your answer...
This should give you the fist level of children (subpages) in your navigation:
<nav class="" role="navigation">
<div class="">
<ol class="">
{% for page in pages.children %}
{% if page.visible %}
{% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
<li class="{{ current_page }}">{{ page.menu }}</li>
{% if page.children %}
<ol class="">
{% for child in page.children %}
{% if child.visible %}
<li class="{{ current_page }}">{{ child.menu }}</li>
{% endif %}
{% endfor %}
</ol>
{% endif %}
{% endif %}
{% endfor %}
</ol>
</div>
</nav>
Related
{% for category in categories %}
{% if request.get_full_path == '/?category={{category.0}}' %}
{{ category.0 }}
<li class="nav-item active">
<span class="sr-only">(current)</span>
<a class="nav-link" href="/?category={{ category.0 }}">{{ category.1 }}</a>
</li>
{% else %}
{{request.get_full_path}}
/?category={{category.0}}
<li class="nav-item">
<span class="sr-only">(current)</span>
<a class="nav-link" href="/?category={{ category.0 }}">{{ category.1 }}</a>
</li>
{% endif %}
{% endfor %}
I want to highlight navigation buttons, but {% if %} statement can't see {{category.0}} expression inside.
Can I use {{}} inside {% if %} statement in jinja?
No you can use your return variable in {% if %}
Without {{}}
I need to display the third level in my navigation. Only the second level is displayed.
Like this:
|- Home
|- About us
|-|- History
|-|-|- WW1
|-|-|- WW2
|- Contact
I still hope there is someone who solved this problem! Thank youuu!
{% for child in children %}
{% if child.is_leaf_node %}
<li>{{ child.get_menu_title }}</li>
{% endif %}
{% if not child.is_leaf_node or child.ancestor %}
<li class="dropdown">{{ child.get_menu_title }} >
<ul class="dropdown-menu xpl1">
{% for kid in child.get_descendants %}
{% if kid.is_leaf_node %}
<li>{{ kid.get_menu_title }}</li>
{% endif %}
{% if not kid.is_leaf_node or kid.ancestor %}
<li class="dropdown">{{ kid.get_menu_title }} >
<ul class="dropdown-menu xpl1">
{% for kidkid in kid.get_descendants %}
<li>{{ kidkid.get_menu_title }}</li>
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
</ul></li>
{% endif %}
{% endfor %} ```
This is old, but I needed to solve the same problem. I combined some of the original code and some from the Github repo mentioned in the comments.
Here is my solution:
{% load menu_tags %}
{% for child in children %}
{% if child.is_leaf_node %}
<li>{{ child.get_menu_title }}</li>
{% endif %}
{% if not child.is_leaf_node or child.ancestor %}
<li class="dropdown child{% if child.selected %} selected{% endif %}{% if child.ancestor %} ancestor{% endif %}{% if child.sibling %} sibling{% endif %}{% if child.descendant %} descendant{% endif %}">
<a class="dropdown-toggle" data-toggle="dropdown" href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title }}</a>
{% if child.children %}
<ul class="dropdown-menu">
{% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
</ul>
{% endif %}
</li>
{% endif %}
{% endfor %}
stack community I'm completely an amateur in HTML, Liquid, Adx, in short programming and applying logic, don't have great understanding.
Im not sure why the <span> Test2 </span> is appearing 2x, as you can see from the image,
I want to achieve the following, Test2 new name? as one text and the left Test2 don't want it to be displayed. Please advise.
{% assign homeurl = website.adx_partialurl %}
<div class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container">
<div id="navbar" class="navbar-collapse collapse">
{% assign primary_nav = weblinks["Primary Navigation"] %}
{% if primary_nav %}
<div class="data-weblinks-maxdepth="">
<ul class="nav navbar-nav weblinks" role="menubar">
{% for link in primary_nav.weblinks %}
<li role="none" class="weblink {% if sublinks.size > 0 %} dropdown{% endif %}">
<a role="menuitem" aria-label="{{ link.name | escape }}" {%- if link.tooltip %} title="{{ link.tooltip | escape }}"
{% endif %}>
<span> Test2 </span>
{%- unless link.display_image_only -%}
{{ link.name | escape }}
{%- endunless -%}
</a>
</li>
{% endfor %}
</ul>
{% editable primary_nav %}
</div>
{% endif %}
</div>
</div>
</div>
To change the name of the link and perhaps add something in front of it all you have to do is add something into the if clause like below:
{% assign homeurl = website.adx_partialurl %}
<div class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container">
<div id="navbar" class="navbar-collapse collapse">
{% assign primary_nav = weblinks["Primary Navigation"] %}
{% if primary_nav %}
<div class="data-weblinks-maxdepth="">
<ul class="nav navbar-nav weblinks" role="menubar">
{% for link in primary_nav.weblinks %}
<li role="none" class="weblink {% if sublinks.size > 0 %} dropdown{% endif %}">
<a role="menuitem" aria-label="{{ link.name | escape }}" {%- if link.tooltip %} title="{{ link.tooltip | escape }}"{% endif %}>
{%- unless link.display_image_only -%}
Text 2 {{ link.name | escape }}
{%- endunless -%}
</a>
</li>
{% endfor %}
</ul>
{% editable primary_nav %}
</div>
{% endif %}
</div>
</div>
</div>
How do I change the for loop to ignore duplicates mealtype == 'Entrees'
I only need it to create 1 <a href>
{% for menu in menus %}
{% if menu.mealtype == 'Entrees' %}
<li role="presentation">
Entrees
</li>
{% endif %}
{% endfor %}
full li
{% for menu in menus %}
{% if menu.show_presentation %}
<li role="presentation">
Entrees
</li>
{% endif %}
{% if menu.show_presentation %}
<li role="presentation">
Sides
</li>
{% endif %}
{% if menu.show_presentation %}
<li role="presentation">
Mains
</li>
{% endif %}
{% if menu.show_presentation %}
<li role="presentation">
Drinks
</li>
{% endif %}
{% if menu.show_presentation %}
<li role="presentation">
Desserts
</li>
{% endif %}
{% if menu.show_presentation %}
<li role="presentation">
Specials
</li>
{% endif %}
{% if menu.show_presentation %}
<li role="presentation">
Others
</li>
{% endif %}
{% endfor %}
Update for view based on comments. Try this:
show_presentation_list = []
menus_presentation = []
for menu in menus:
if menu.mealtype and menu.mealtype not in show_presentation_list:
show_presentation_list.append(menu.mealtype)
menus_presentation.append(menu)
Also your new template, try this:
{% for menu in menus_presentation %}
<li role="presentation">
{{menu.mealtype}}
</li>
{% endfor %}
how can i create an outline like this code will produce
<ol type="1">
<li>Fruit
<ol type="a">
<li>Apples</li>
<li>Bananas</li>
<li>Oranges</li>
</ol>
</li>
<li>Vegetables
<ol type="a">
<li>Carrots</li>
<li>Lettuce</li>
<li>Cucumbers</li>
</ol>
</li>
</ol>
but in jinja2... i tried this, and it just doesn't want to work
{% for project in P %}
<ol>
<li> Project: {{ project.name }}
{% for pgoal in project.goals.all() %}
<ol type="A">
{% if loop.last %}</ol></li>{% endif %}
<li>Goal: {{ pgoal.goal }}</li>
{% for pstrat in pgoal.strategies.all() %}
{% if loop.last %}</ol></li>{% endif %}
<ol type="a">
<li> Strategy: {{ pstrat.strategy }}</li>
{% for ptask in pstrat.tasks.all() %}
<li>Task: {{ ptask.task }} complete? {{ptask.complete}}</li>
<ol type="1">
{% if loop.last %}</ol></li>{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
Something like this would show a nested <ol> structure for your nested objects:
<ol>
{% for project in P %}
<li> Project: {{ project.name }}
<ol type="A">
{% for pgoal in project.goals.all() %}
<li>Goal: {{ pgoal.goal }}
<ol type="a">
{% for pstrat in pgoal.strategies.all() %}
<li> Strategy: {{ pstrat.strategy }}
<ol type="1">
{% for ptask in pstrat.tasks.all() %}
<li>Task: {{ ptask.task }} complete? {{ptask.complete}}</li>
{% endfor %}
</ol>
</li>
{% endfor %}
</ol>
</li>
{% endfor %}
</ol>
</li>
{% endfor %}
</ol>