1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-12-02 19:17:21 +01:00

Simplified conditionals in templates

This commit is contained in:
squidfunk 2020-11-07 16:09:06 +01:00
parent a46b42c5e2
commit acc4a273c4
5 changed files with 31 additions and 59 deletions

View File

@ -7,11 +7,8 @@
{% endif %} {% endif %}
{% if nav_item.children %} {% if nav_item.children %}
<li class="{{ class }} md-nav__item--nested"> <li class="{{ class }} md-nav__item--nested">
{% if nav_item.active %} {% set checked = "checked" if nav_item.active %}
<input class="md-nav__toggle md-toggle" data-md-toggle="{{ path }}" type="checkbox" id="{{ path }}" checked> <input class="md-nav__toggle md-toggle" data-md-toggle="{{ path }}" type="checkbox" id="{{ path }}" {{ checked }}>
{% else %}
<input class="md-nav__toggle md-toggle" data-md-toggle="{{ path }}" type="checkbox" id="{{ path }}">
{% endif %}
<label class="md-nav__link" for="{{ path }}"> <label class="md-nav__link" for="{{ path }}">
{{ nav_item.title }} {{ nav_item.title }}
<span class="md-nav__icon md-icon"></span> <span class="md-nav__icon md-icon"></span>

View File

@ -3,15 +3,13 @@
-#} -#}
{% if nav_item.is_homepage or nav_item.url == "index.html" %} {% if nav_item.is_homepage or nav_item.url == "index.html" %}
<li class="md-tabs__item"> <li class="md-tabs__item">
{% set class = "md-tabs__link" %}
{% if not page.ancestors | length and nav | selectattr("url", page.url) %} {% if not page.ancestors | length and nav | selectattr("url", page.url) %}
<a href="{{ nav_item.url | url }}" class="md-tabs__link md-tabs__link--active"> {% set class = "md-tabs__link md-tabs__link--active" %}
{{ nav_item.title }}
</a>
{% else %}
<a href="{{ nav_item.url | url }}" class="md-tabs__link">
{{ nav_item.title }}
</a>
{% endif %} {% endif %}
<a href="{{ nav_item.url | url }}" class="{{ class }}">
{{ nav_item.title }}
</a>
</li> </li>
{% elif nav_item.children and nav_item.children | length > 0 %} {% elif nav_item.children and nav_item.children | length > 0 %}
{% set title = title | default(nav_item.title) %} {% set title = title | default(nav_item.title) %}
@ -20,15 +18,13 @@
{% include "partials/tabs-item.html" %} {% include "partials/tabs-item.html" %}
{% else %} {% else %}
<li class="md-tabs__item"> <li class="md-tabs__item">
{% set class = "md-tabs__link" %}
{% if nav_item.active %} {% if nav_item.active %}
<a href="{{ (nav_item.children | first).url | url }}" class="md-tabs__link md-tabs__link--active"> {% set class = "md-tabs__link md-tabs__link--active" %}
{{ title }}
</a>
{% else %}
<a href="{{ (nav_item.children | first).url | url }}" class="md-tabs__link">
{{ title }}
</a>
{% endif %} {% endif %}
<a href="{{ (nav_item.children | first).url | url }}" class="{{ class }}">
{{ title }}
</a>
</li> </li>
{% endif %} {% endif %}
{% elif nav_item.url.startswith("http") %} {% elif nav_item.url.startswith("http") %}

View File

@ -31,22 +31,14 @@
<li class="{{ class }} md-nav__item--nested"> <li class="{{ class }} md-nav__item--nested">
<!-- Active checkbox expands items contained within nested section --> <!-- Active checkbox expands items contained within nested section -->
{% if nav_item.active %} {% set checked = "checked" if nav_item.active %}
<input <input
class="md-nav__toggle md-toggle" class="md-nav__toggle md-toggle"
data-md-toggle="{{ path }}" data-md-toggle="{{ path }}"
type="checkbox" type="checkbox"
id="{{ path }}" id="{{ path }}"
checked {{ checked }}
/> />
{% else %}
<input
class="md-nav__toggle md-toggle"
data-md-toggle="{{ path }}"
type="checkbox"
id="{{ path }}"
/>
{% endif %}
<!-- Expand active pages --> <!-- Expand active pages -->
<label class="md-nav__link" for="{{ path }}"> <label class="md-nav__link" for="{{ path }}">

View File

@ -22,7 +22,7 @@
{% import "partials/language.html" as lang with context %} {% import "partials/language.html" as lang with context %}
<!-- Support for mkdocs-git-revision-date-localized-plugin --> <!-- Last updated date -->
{% set label = lang.t("source.revision.date") %} {% set label = lang.t("source.revision.date") %}
<hr /> <hr />
<div class="md-source-date"> <div class="md-source-date">

View File

@ -23,18 +23,13 @@
<!-- Home page --> <!-- Home page -->
{% if nav_item.is_homepage or nav_item.url == "index.html" %} {% if nav_item.is_homepage or nav_item.url == "index.html" %}
<li class="md-tabs__item"> <li class="md-tabs__item">
{% set class = "md-tabs__link" %}
{% if not page.ancestors | length and nav | selectattr("url", page.url) %} {% if not page.ancestors | length and nav | selectattr("url", page.url) %}
<a {% set class = "md-tabs__link md-tabs__link--active" %}
href="{{ nav_item.url | url }}"
class="md-tabs__link md-tabs__link--active"
>
{{ nav_item.title }}
</a>
{% else %}
<a href="{{ nav_item.url | url }}" class="md-tabs__link">
{{ nav_item.title }}
</a>
{% endif %} {% endif %}
<a href="{{ nav_item.url | url }}" class="{{ class }}">
{{ nav_item.title }}
</a>
</li> </li>
<!-- Main navigation item with nested items --> <!-- Main navigation item with nested items -->
@ -49,21 +44,13 @@
<!-- Render item --> <!-- Render item -->
{% else %} {% else %}
<li class="md-tabs__item"> <li class="md-tabs__item">
{% set class = "md-tabs__link" %}
{% if nav_item.active %} {% if nav_item.active %}
<a {% set class = "md-tabs__link md-tabs__link--active" %}
href="{{ (nav_item.children | first).url | url }}"
class="md-tabs__link md-tabs__link--active"
>
{{ title }}
</a>
{% else %}
<a
href="{{ (nav_item.children | first).url | url }}"
class="md-tabs__link"
>
{{ title }}
</a>
{% endif %} {% endif %}
<a href="{{ (nav_item.children | first).url | url }}" class="{{ class }}">
{{ title }}
</a>
</li> </li>
{% endif %} {% endif %}