j2cli icon indicating copy to clipboard operation
j2cli copied to clipboard

Support multiple template dirs

Open kmpm opened this issue 6 years ago • 5 comments

I would love to have support for multiple template dirs to solve relative imports. Something on the line to what is suggested here https://stackoverflow.com/questions/2180247/does-the-jinja2-templating-language-have-the-concept-of-here-current-director

kmpm avatar Apr 25 '19 21:04 kmpm

Can you please give me an example of how would you like j2 to behave? Are you talking about the inclusion of other template files from the one that you pass as an argument?

kolypto avatar Apr 26 '19 21:04 kolypto

@kmpm bump? :)

kolypto avatar Jun 04 '19 09:06 kolypto

I believe @kmpm is referring to the ability to add

{% include "some-template.j2" %}

and have j2cli search a set of paths to locate a template with that name.

For example, https://stackoverflow.com/questions/35802741/jinja-cant-find-template-path

I've run into this issue as well. It's not clear where the {% include ... %} directive will search for templates. I've created a folder

/templates/mytemplate.j2 /templates/common.j2

and tried to include common.j2 into mytemplate.j2 but generate a jinja2.exceptions.TemplateNotFound exception.

nkabir avatar Sep 30 '20 13:09 nkabir

It would be nice to use {% extends "base.j2" %} and {% include "favorite/macros.j2" %}

And it seems possible using absolue paths if templates are in other directory: https://github.com/kolypto/j2cli/blob/master/j2cli/cli.py#L28

luchaninov avatar Jun 14 '22 19:06 luchaninov

Exactly as @luchaninov describes. To be able to extend and include without absolute paths is a minimum. Some kind of "by convention" or configurable search paths would be nice.

kmpm avatar Jun 27 '22 09:06 kmpm