From 0512f18f11b2ba9432a8be8eb2c05b6e290b976b Mon Sep 17 00:00:00 2001 From: Gordon Messmer Date: Mon, 17 Nov 2014 11:04:22 -0800 Subject: Add examples for the "include" and "extends" tags in Jinja2. --- .../plugins/generators/examples/jinja2/extends.txt | 61 ++++++++++++++++++++++ .../plugins/generators/examples/jinja2/include.txt | 54 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 doc/server/plugins/generators/examples/jinja2/extends.txt create mode 100644 doc/server/plugins/generators/examples/jinja2/include.txt (limited to 'doc') diff --git a/doc/server/plugins/generators/examples/jinja2/extends.txt b/doc/server/plugins/generators/examples/jinja2/extends.txt new file mode 100644 index 000000000..a0eeb5c03 --- /dev/null +++ b/doc/server/plugins/generators/examples/jinja2/extends.txt @@ -0,0 +1,61 @@ +.. -*- mode: rst -*- + +========================= + Extending Jinja2 Templates +========================= + +Jinja2 templates can use the {% extends %} directive to inherit file +fragments which might be common to many configuration files. + +Use the "jinja2_include" suffix for file fragments you will extend. + +``/var/lib/bcfg2/Cfg/foo/common.jinja2_include`` + +.. code-block:: none + + [global] + setting1 = true + setting2 = false + {% block setting3 %}setting3 = "default value"{% endblock %} + + {% block section1 -%} + [section1] + setting4 = true + setting5 = false + {%- endblock %} + + {% block section2 -%} + [section2] + setting6 = true + setting7 = false + {%- endblock %} + +``/var/lib/bcfg2/Cfg/foo/foo.H_hostname.jinja2`` + +.. code-block:: none + + {% extends "common.jinja2_include" %} + {% block setting3 %}setting3 = "new value"{% endblock %} + {% block section1 -%} + [section1] + setting4 = false + setting5 = false + {%- endblock %} + +Output +====== + +.. code-block:: none + + [global] + setting1 = true + setting2 = false + setting3 = "new value" + + [section1] + setting4 = false + setting5 = false + + [section2] + setting6 = true + setting7 = false diff --git a/doc/server/plugins/generators/examples/jinja2/include.txt b/doc/server/plugins/generators/examples/jinja2/include.txt new file mode 100644 index 000000000..49be7c277 --- /dev/null +++ b/doc/server/plugins/generators/examples/jinja2/include.txt @@ -0,0 +1,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 -- cgit v1.2.3-1-g7c22