Debian Codegraph @

examples/basics/10_jinja2_templating/templates/macros.jinja2

raw
1
2 {# Macro that renders a bounding box element from feature list #}
3 {% macro render_bounded_by(features) -%}
4
5 {# first assemble all latitudes and longitudes #}
6 {% set longitudes = [] %}
7 {% set latitudes = [] %}
8
9 {% for feature in features %}
10 {% do longitudes.append(feature.lon) %}
11 {% do latitudes.append(feature.lat) %}
12 {% endfor %}
13
14 <!-- Rendered by macro render_bounded_by() -->
15 {# use the maximum and minimum Jinja2 Filters to get max/min from lists #}
16 <gml:boundedBy>
17 <gml:Box>
18 <gml:coord>
19 <gml:X>{{ longitudes|minimum }}</gml:X>
20 <gml:Y>{{ latitudes|minimum }}</gml:Y>
21 </gml:coord>
22 <gml:coord>
23 <gml:X>{{ longitudes|maximum }}</gml:X>
24 <gml:Y>{{ latitudes|maximum }}</gml:Y>
25 </gml:coord>
26 </gml:Box>
27 </gml:boundedBy>
28 {%- endmacro %}
29
30 {# Macro that renders a name element #}
31 {% macro render_name(name) -%}
32 <!-- Rendered by macro render_name() -->
33 <gml:name>
34 {{ name }}
35 </gml:name>
36 {%- endmacro %}
37
38 {# Macro that renders any element with tag and content :-) #}
39 {% macro render_element(tag, content) -%}
40 <!-- Rendered by macro render_element() -->
41 <{{tag}}>
42 {{ content }}
43 </{{tag}}>
44 {%- endmacro %}