mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 07:20:55 +00:00
Fix book code examples
This commit is contained in:
parent
edcaa61fb6
commit
1da2840071
@ -104,7 +104,7 @@ Output:
|
|||||||
### default
|
### default
|
||||||
[#default]: #default
|
[#default]: #default
|
||||||
|
|
||||||
```jinja
|
```text
|
||||||
{{ variable_or_expression | default(default_value) }}
|
{{ variable_or_expression | default(default_value) }}
|
||||||
{{ variable_or_expression | default(default_value, [[boolean =] true]) }}
|
{{ variable_or_expression | default(default_value, [[boolean =] true]) }}
|
||||||
```
|
```
|
||||||
@ -285,7 +285,7 @@ enabled by <code>"alloc"</code><br/>
|
|||||||
enabled by <code>"default"</code>
|
enabled by <code>"default"</code>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
```jinja
|
```text
|
||||||
{{ "format_string" | format([variables ...]) }}
|
{{ "format_string" | format([variables ...]) }}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -468,7 +468,7 @@ hello
|
|||||||
### `pluralize`
|
### `pluralize`
|
||||||
[#pluralize]: #pluralize
|
[#pluralize]: #pluralize
|
||||||
|
|
||||||
```jinja
|
```text
|
||||||
{{ integer | pluralize }}
|
{{ integer | pluralize }}
|
||||||
{{ integer | pluralize([singular = ""], [plural = "s"]) }}
|
{{ integer | pluralize([singular = ""], [plural = "s"]) }}
|
||||||
```
|
```
|
||||||
|
@ -557,7 +557,7 @@ const x = {{ x is defined }};
|
|||||||
Due to proc-macro limitations, askama can only see the fields of your current type and the variables
|
Due to proc-macro limitations, askama can only see the fields of your current type and the variables
|
||||||
declared in the templates. Because of this, you can not check if a field or a function is defined:
|
declared in the templates. Because of this, you can not check if a field or a function is defined:
|
||||||
|
|
||||||
```jinja
|
```jinja,error
|
||||||
{% if x.y is defined %}
|
{% if x.y is defined %}
|
||||||
This code will not compile
|
This code will not compile
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -650,7 +650,7 @@ you can also use an optional `{% endwhen %}` node to close a `{% when %}` case:
|
|||||||
{% when 1 | 3 | 5 | 7 | 9 %}
|
{% when 1 | 3 | 5 | 7 | 9 %}
|
||||||
odd
|
odd
|
||||||
{% endwhen %}
|
{% endwhen %}
|
||||||
{% else }
|
{% else %}
|
||||||
unknown
|
unknown
|
||||||
{% endmatch %}
|
{% endmatch %}
|
||||||
```
|
```
|
||||||
@ -885,7 +885,7 @@ To have a small library of reusable snippets, it's best to declare the macros in
|
|||||||
Additionally to specifying arguments positionally, you can also pass arguments by name. This allows passing the arguments in any order:
|
Additionally to specifying arguments positionally, you can also pass arguments by name. This allows passing the arguments in any order:
|
||||||
|
|
||||||
```jinja
|
```jinja
|
||||||
{% macro heading(title, font_weight = "normal", font_size = 13)}
|
{% macro heading(title, font_weight = "normal", font_size = 13) %}
|
||||||
<h1 style="font-weight: {{ font_weight }}; font-size: {{ font_size }};">
|
<h1 style="font-weight: {{ font_weight }}; font-size: {{ font_size }};">
|
||||||
{{ title }}
|
{{ title }}
|
||||||
</h1>
|
</h1>
|
||||||
@ -949,7 +949,7 @@ Invoking this macro using the call expression syntax shown above (`{{ centered()
|
|||||||
However, you can declare macros in a way that allows invoking them with and without body:
|
However, you can declare macros in a way that allows invoking them with and without body:
|
||||||
|
|
||||||
```jinja
|
```jinja
|
||||||
{% macro render_dialog(title, class='dialog') -%}
|
{% macro render_dialog(title, class="dialog") -%}
|
||||||
<div class="{{ class }}">
|
<div class="{{ class }}">
|
||||||
<h2>{{ title }}</h2>
|
<h2>{{ title }}</h2>
|
||||||
<div class="contents">
|
<div class="contents">
|
||||||
@ -1010,7 +1010,7 @@ Macro invocations instantly overwrite the `caller` variable with their own. To b
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
{{ caller() }}
|
{{ caller() }}
|
||||||
</div>
|
</div>
|
||||||
{% endmacro }
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro outer_container() %}
|
{% macro outer_container() %}
|
||||||
{# Create an alias to our `caller`, so we can access it within container: #}
|
{# Create an alias to our `caller`, so we can access it within container: #}
|
||||||
@ -1020,7 +1020,7 @@ Macro invocations instantly overwrite the `caller` variable with their own. To b
|
|||||||
{# nested macro invocation - will overwrite the `caller` variable: #}
|
{# nested macro invocation - will overwrite the `caller` variable: #}
|
||||||
{% call container() %}
|
{% call container() %}
|
||||||
{{ outer_caller() }}
|
{{ outer_caller() }}
|
||||||
{% endmacro %}
|
{% endcall %}
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user