I'm trying to use a sandboxed Jinja2 environment to handle template customizations.
I've tried using both a DictLoader and FunctionLoader, but keep running into similar issues... I'm mostly concerned with FunctionLoader now.
I can't manage to include
or import
another template (which contains macros). The FuctionLoader's specified "load" function is never called for the referenced templates.
I've tried with no luck:
I'm sure there's got to be a way to support this - can someone point me in the right direction ?
Macros within Jinja2 are essentially used like functions with Python and are great for repeating configs with identical structures (think interface configurations, ASA object-groups, etc).
from_string . Jinja 2 provides a Template class that can be used to do the same, but with optional additional configuration. Jinja 1 performed automatic conversion of bytes in a given encoding into unicode objects.
The import syntax must use quoted strings.
Bad:
{% import utils %}
{% import utils.macros as macros %}
{% from utils.macros import macro_1 , macro_2 %}
Good:
{% import "utils" as utils %}
{% import "utils.macros" as macros %}
{% from "utils.macros" import macro_1 , macro_2 %}
The quoted string is passed into the FunctionLoader
or used as the key with the DictLoader
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With