{% 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 {{}}
Related
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>
I have a category called "tachartasan" which I have excluded from my index page however the posts in this category are still being counted in the pagination which is currently set to 10 posts per page.
7 of my most recent posts have been in the tachartasan category and it has resulted in my front page showing only 3 posts total.
<div class="container">
{% for post in paginator.posts %}
{% unless post.categories contains 'tachartasan' %}
<div class="row">
<div class="col-md-3">
<img src="{{ post.image }}" class="index-image">
</div>
<div class="col-md-9">
<h5 class="post-title">{{ post.title }}</h5>
{% if post.author %}
<p class="text-muted">{{ post.date | date: "%Y-%m-%d" }} le {{ post.author }}</p>
{% else %}
<p class="text-muted">{{ post.date | date: "%Y-%m-%d" }} le Crìstean MacMhìcheil</p>
{% endif %}
{{ post.excerpt }}
</div>
</div>
<hr/>
{% endunless %}
{% endfor %}
<!-- Pagination -->
<nav>
<ul class="pagination justify-content-center pagination-lg">
{% if paginator.next_page %}
<li class="page-item">
<a class="page-link" href="{{ site.baseurl }}/duilleag-{{paginator.next_page}}">
<i class="fas fa-arrow-left"></i>
</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="{{ site.baseurl }}/">
<i class="fas fa-arrow-left"></i>
</a>
</li>
{% endif %}
<li class="page-item disabled">
<a class="page-link" href="{{ site.baseurl }}/">
Duilleag {{ paginator.page }} / {{ paginator.total_pages }}
</a>
</li>
{% if paginator.previous_page %}
{% if paginator.page == 2 %}
<li class="page-item">
<a class="page-link" href="{{ site.baseurl }}/">
<i class="fas fa-arrow-right"></i>
</a>
</li>
{% else %}
<li class="page-item">
<a class="page-link" href="{{ site.baseurl }}/duilleag-{{paginator.previous_page}}">
<i class="fas fa-arrow-right"></i>
</a>
</li>
{% endif %}
{% else %}
<li class="page-item disabled">
<a class="page-link" href="{{ site.baseurl }}/">
<i class="fas fa-arrow-right"></i>
</a>
</li>
{% endif %}
</ul>
</nav>
</div>
I don't want the hidden "tachartasan" posts to be counted as part of the 10 posts per page.
Adding this line to the front matter of my excluded posts solved it. They are hidden on the index page and no longer counted against the pagination limit and are still visible on the specific category page.
hidden: true
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 %}
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>