Hi team, wondering about some pointers for working...
# questions
m
Hi team, wondering about some pointers for working with jinja2 templating. Facing the following pain point: • We're importing .j2 files that keep macros and some variables, however we can only import j2 files that are in the same folder or in subfolders: ◦ I Can do {% from "./countries.j2" import countries %} with no problem ◦ Can't do {% from "../countries.j2" import countries %} which ends giving an error • Ideally I'd keep a "global" templates folder from which macros and variables can be imported • Not sure if this is directly a kedro question. Wondering if some subclassing to TemplatedConfigLoader could do the trick
d
Hi Miguel - so this has been done before, as of today you need to override one line in TemplatedConfigLoader to get it working. I’ll explain how to do this on the latest version of Kedro, however in the near future this will change as we move to OmegeConf which will introduce a whole host of new fancy features here. On this line where
anyconfi.load()
is called you can provide a
paths
argument which points to wherever you provide your global list of templates are, these will be in scope for any templating https://github.com/kedro-org/kedro/blob/3b3e92b2f6ba0f3da227994322876eeff736628d/kedro/config/common.py#L135 In the future this will be better, part of the reason OmegaConf is coming is because we’re in the process of rewriting and simplifying the config loader which has essentially existed since day 1 of Kedro and is well overdue a refactor.
m
Thank you for all the detail!