Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_jinja2_renderer name only works for default search path #144

Open
russellballestrini opened this issue Jul 2, 2017 · 1 comment
Open

Comments

@russellballestrini
Copy link

russellballestrini commented Jul 2, 2017

Background

If mypackage/__init__.py adds a jinja renderer with a custom name value, only the directory mypackage/templates is searched.

For example:

config.add_jinja2_renderer('.j2')
config.add_jinja2_search_path('anotherpackage:templates/')

In this case .j2 files in another package will not be found because the name='.jinja2' by default on the add_jinja2_search_path function.

Expected Behavior

The add_jinja2_renderer will "register" into the Pyramid renderer system that .j2 files should always be rendered using Jinja2, regardless of the package / search path.

The state of the .j2 registration would be captured and used in other functions/methods.

Actual Behavior

The add_jinja2_renderer function / method only registers .j2 files for the default search path, any additional search paths need to pass the extension name.

Work around

config.add_jinja2_renderer('.j2')
config.add_jinja2_search_path('anotherpackage:templates/', name='.j2')
@mmerickel
Copy link
Member

mmerickel commented Jul 2, 2017

That's not a workaround - that's the intended solution. pyramid_jinja2 allows you to define separate rendering systems for various file types. It is all documented this way. For example in add_jinja2_search_path: It will add the directory or :term:`asset specification` passed as ``searchpath`` to the current search path of the :class:`jinja2.Environment` used by the renderer identified by ``name``.

An option that has come up before but no one has implemented yet is something like add_jinja2_renderer('.j2', alias='.jinja2') or something like that. Alternatively we could just change the semantics such that renderers defined from the same settings namespace share the same environment - I would be ok with this change as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants