]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Allow instantiating template dataclasses in jinja2 templates
authorNicki Křížek <nicki@isc.org>
Wed, 1 Apr 2026 17:42:38 +0000 (19:42 +0200)
committerNicki Křížek <nicki@isc.org>
Wed, 27 May 2026 14:19:31 +0000 (14:19 +0000)
In some cases, the template data might need to be set directly in the
jinja2 templates using `{% set %}`. Expose the template dataclasses to
the templates so we can use these existing classes, rather than creating
ad-hoc data containers.

bin/tests/system/isctest/template.py

index f81b423f10d193e8cc95a2176b91d6132603fc1a..8065f4acbbd8a862ac39dd32e26805b8a6fb2494 100644 (file)
@@ -45,6 +45,11 @@ class TemplateEngine:
             variable_start_string="@",
             variable_end_string="@",
         )
+        # allow instantiating the template dataclasses in jinja2 templates when
+        # using {% set %}
+        self.j2env.globals["Nameserver"] = Nameserver
+        self.j2env.globals["TrustAnchor"] = TrustAnchor
+        self.j2env.globals["Zone"] = Zone
 
     def render(
         self,