Debian Codegraph @

demo/kitchen-sink/docs/nunjucks.nunjucks

raw
1 {{ foo.bar }}
2 {{ foo["bar"] }}
3 {{ foo | title }}
4 {{ foo | join(",") }}
5 {{ foo | replace("foo", "bar") | capitalize }}
6 {% block header %}
7 This is the default content
8 {% endblock %}
9
10 <section class="left">
11 {% block left %}{% endblock %}
12 </section>
13
14 <section class="right">
15 {% block right %}
16 This is more content
17 {% endblock %}
18 </section>
19 {% extends "parent.html" %}
20
21 {% block left %}
22 This is the left side!
23 {% endblock %}
24
25 {% block right %}
26 This is the right side!
27 {% endblock %}
28
29 {% block right %}
30 {{ super() }}
31 Right side!
32 {% endblock %}
33
34 {% if variable %}
35 It is true
36 {% endif %}
37
38 {% if hungry %}
39 I am hungry
40 {% elif tired %}
41 I am tired
42 {% else %}
43 I am good!
44 {% endif %}
45
46 <h1>Posts</h1>
47 <ul>
48 {% for item in items %}
49 <li>{{ item.title }}</li>
50 {% else %}
51 <li>This would display if the 'item' collection were empty</li>
52 {% endfor %}
53 </ul>
54
55 {% for ingredient, amount in food %}
56 Use {{ amount }} of {{ ingredient }}
57 {% endfor %}
58
59 {% for fruit, color in fruits %}
60 Did you know that {{ fruit }} is {{ color }}?
61 {% endfor %}
62
63 {% for x, y, z in points %}
64 Point: {{ x }}, {{ y }}, {{ z }}
65 {% endfor %}
66
67 <h1>Posts</h1>
68 <ul>
69 {% asyncEach item in items %}
70 {% include "item-template.html" %}
71 {% endeach %}
72 </ul>
73
74 <h1>Posts</h1>
75 <ul>
76 {% asyncAll item in items %}
77 <li>{{ item.id | lookup }}</li>
78 {% endall %}
79 </ul>
80
81 {% macro field(name, value='', type='text') %}
82 <div class="field">
83 <input type="{{ type }}" name="{{ name }}"
84 value="{{ value | escape }}" />
85 </div>
86 {% endmacro %}
87
88 {{ username }}
89 {% set username = "joe" %}
90 {{ username }}
91
92 {% set standardModal %}
93 {% include 'standardModalData.html' %}
94 {% endset %}
95
96 <div class="js-modal" data-modal="{{standardModal | e}}">
97
98 {% set standardModal %}
99 {% include 'standardModalData.html' %}
100 {% endset %}
101
102 <div class="js-modal" data-modal="{{standardModal | e}}">
103
104 {% include "missing.html" ignore missing %}
105
106 {% import "forms.html" as forms %}
107
108 {{ forms.label('Username') }}
109 {{ forms.field('user') }}
110 {{ forms.label('Password') }}
111 {{ forms.field('pass', type='password') }}
112
113 {% from "forms.html" import field, label as description %}
114
115 {{ description('Username') }}
116 {{ field('user') }}
117 {{ description('Password') }}
118 {{ field('pass', type='password') }}
119
120 {{ foo(1, 2, bar=3, baz=4) }}
121
122 {# Loop through all the users #}
123 {% for user in users %}...{% endfor %}
124
125
126 {% set cls = cycler("odd", "even") %}
127 {% for row in rows %}
128 <div class="{{ cls.next() }}">{{ row.name }}</div>
129 {% endfor %}