summaryrefslogtreecommitdiffstats
path: root/doc/server/plugins/generators/examples/jinja2/include.txt
blob: 49be7c277b72b3a2a594290d7ae14515d433e06f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
.. -*- mode: rst -*-

=========================
 Including Jinja2 Templates
=========================

Jinja2 templates can use the {% include %} directive to include file 
fragments which might be common to many configuration files.

Use the "jinja2_include" suffix for file fragments you will include.

``/var/lib/bcfg2/Cfg/foo/foo.jinja2``

.. code-block:: none

    [global]
    setting1 = true
    setting2 = false
    
    {% for x in metadata.groups %}{% include x + '.jinja2_include' ignore missing %}
    {% endfor %}

``/var/lib/bcfg2/Cfg/foo/group1.jinja2_include``

.. code-block:: none

    [group1]
    setting3 = true
    setting4 = false

``/var/lib/bcfg2/Cfg/foo/group3.jinja2_include``

.. code-block:: none

    [group3]
    setting7 = true
    setting8 = false

Output
======

.. code-block:: none

    [global]
    setting1 = true
    setting2 = false
    
    [group1]
    setting3 = true
    setting4 = false

    [group3]
    setting7 = true
    setting8 = false