Skip to content

Commit

Permalink
deploy: 21f840a
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Nov 28, 2023
1 parent f86cac4 commit 2c41a4a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 8 deletions.
35 changes: 32 additions & 3 deletions print.html
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ <h2 id="recursive-structures"><a class="header" href="#recursive-structures">Rec
<h2 id="macros"><a class="header" href="#macros">Macros</a></h2>
<p>You can define macros within your template by using <code>{% macro name(args) %}</code>, ending with <code>{% endmacro %}</code>.</p>
<p>You can then call it with <code>{% call name(args) %}</code>:</p>
<pre><code>{% macro heading(arg) %}
<pre><code class="language-jinja">{% macro heading(arg) %}

&lt;h1&gt;{{arg}}&lt;/h1&gt;

Expand All @@ -954,12 +954,41 @@ <h2 id="macros"><a class="header" href="#macros">Macros</a></h2>
{% call heading(s) %}
</code></pre>
<p>You can place macros in a separate file and use them in your templates by using <code>{% import %}</code>:</p>
<pre><code>{%- import &quot;macro.html&quot; as scope -%}
<pre><code class="language-jinja">{%- import &quot;macro.html&quot; as scope -%}

{% call scope::heading(s) %}
</code></pre>
<p>You can optionally specify the name of the macro in <code>endmacro</code>:</p>
<pre><code class="language-html">{% macro heading(arg) %}&lt;p&gt;{{arg}}&lt;/p&gt;{% endmacro heading %}
<pre><code class="language-jinja">{% macro heading(arg) %}&lt;p&gt;{{arg}}&lt;/p&gt;{% endmacro heading %}
</code></pre>
<p>You can also specify arguments by their name (as defined in the macro):</p>
<pre><code class="language-jinja">{% macro heading(arg, bold) %}

&lt;h1&gt;{{arg}} &lt;b&gt;{{bold}}&lt;/b&gt;&lt;/h1&gt;

{% endmacro %}

{% call heading(bold=&quot;something&quot;, arg=&quot;title&quot;) %}
</code></pre>
<p>You can use whitespace characters around <code>=</code>:</p>
<pre><code class="language-jinja">{% call heading(bold = &quot;something&quot;, arg = &quot;title&quot;) %}
</code></pre>
<p>You can mix named and non-named arguments when calling a macro:</p>
<pre><code>{% call heading(&quot;title&quot;, bold=&quot;something&quot;) %}
</code></pre>
<p>However please note than named arguments must always come <strong>last</strong>.</p>
<p>Another thing to note, if a named argument is referring to an argument that would
be used for a non-named argument, it will error:</p>
<pre><code class="language-jinja">{% macro heading(arg1, arg2, arg3, arg4) %}
{% endmacro %}

{% call heading(&quot;something&quot;, &quot;b&quot;, arg4=&quot;ah&quot;, arg2=&quot;title&quot;) %}
</code></pre>
<p>In here it's invalid because <code>arg2</code> is the second argument and would be used by
<code>&quot;b&quot;</code>. So either you replace <code>&quot;b&quot;</code> with <code>arg3=&quot;b&quot;</code> or you pass <code>&quot;title&quot;</code> before:</p>
<pre><code class="language-jinja">{% call heading(&quot;something&quot;, arg3=&quot;b&quot;, arg4=&quot;ah&quot;, arg2=&quot;title&quot;) %}
{# Equivalent of: #}
{% call heading(&quot;something&quot;, &quot;title&quot;, &quot;b&quot;, arg4=&quot;ah&quot;) %}
</code></pre>
<div style="break-before: page; page-break-before: always;"></div><h1 id="filters-1"><a class="header" href="#filters-1">Filters</a></h1>
<p>Values such as those obtained from variables can be post-processed
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion searchindex.json

Large diffs are not rendered by default.

35 changes: 32 additions & 3 deletions template_syntax.html
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ <h2 id="recursive-structures"><a class="header" href="#recursive-structures">Rec
<h2 id="macros"><a class="header" href="#macros">Macros</a></h2>
<p>You can define macros within your template by using <code>{% macro name(args) %}</code>, ending with <code>{% endmacro %}</code>.</p>
<p>You can then call it with <code>{% call name(args) %}</code>:</p>
<pre><code>{% macro heading(arg) %}
<pre><code class="language-jinja">{% macro heading(arg) %}

&lt;h1&gt;{{arg}}&lt;/h1&gt;

Expand All @@ -630,12 +630,41 @@ <h2 id="macros"><a class="header" href="#macros">Macros</a></h2>
{% call heading(s) %}
</code></pre>
<p>You can place macros in a separate file and use them in your templates by using <code>{% import %}</code>:</p>
<pre><code>{%- import &quot;macro.html&quot; as scope -%}
<pre><code class="language-jinja">{%- import &quot;macro.html&quot; as scope -%}

{% call scope::heading(s) %}
</code></pre>
<p>You can optionally specify the name of the macro in <code>endmacro</code>:</p>
<pre><code class="language-html">{% macro heading(arg) %}&lt;p&gt;{{arg}}&lt;/p&gt;{% endmacro heading %}
<pre><code class="language-jinja">{% macro heading(arg) %}&lt;p&gt;{{arg}}&lt;/p&gt;{% endmacro heading %}
</code></pre>
<p>You can also specify arguments by their name (as defined in the macro):</p>
<pre><code class="language-jinja">{% macro heading(arg, bold) %}

&lt;h1&gt;{{arg}} &lt;b&gt;{{bold}}&lt;/b&gt;&lt;/h1&gt;

{% endmacro %}

{% call heading(bold=&quot;something&quot;, arg=&quot;title&quot;) %}
</code></pre>
<p>You can use whitespace characters around <code>=</code>:</p>
<pre><code class="language-jinja">{% call heading(bold = &quot;something&quot;, arg = &quot;title&quot;) %}
</code></pre>
<p>You can mix named and non-named arguments when calling a macro:</p>
<pre><code>{% call heading(&quot;title&quot;, bold=&quot;something&quot;) %}
</code></pre>
<p>However please note than named arguments must always come <strong>last</strong>.</p>
<p>Another thing to note, if a named argument is referring to an argument that would
be used for a non-named argument, it will error:</p>
<pre><code class="language-jinja">{% macro heading(arg1, arg2, arg3, arg4) %}
{% endmacro %}

{% call heading(&quot;something&quot;, &quot;b&quot;, arg4=&quot;ah&quot;, arg2=&quot;title&quot;) %}
</code></pre>
<p>In here it's invalid because <code>arg2</code> is the second argument and would be used by
<code>&quot;b&quot;</code>. So either you replace <code>&quot;b&quot;</code> with <code>arg3=&quot;b&quot;</code> or you pass <code>&quot;title&quot;</code> before:</p>
<pre><code class="language-jinja">{% call heading(&quot;something&quot;, arg3=&quot;b&quot;, arg4=&quot;ah&quot;, arg2=&quot;title&quot;) %}
{# Equivalent of: #}
{% call heading(&quot;something&quot;, &quot;title&quot;, &quot;b&quot;, arg4=&quot;ah&quot;) %}
</code></pre>

</main>
Expand Down

0 comments on commit 2c41a4a

Please sign in to comment.