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

DebugUndefined does not retain filters in variable #1888

Closed
paimoe opened this issue Sep 15, 2023 · 1 comment
Closed

DebugUndefined does not retain filters in variable #1888

paimoe opened this issue Sep 15, 2023 · 1 comment

Comments

@paimoe
Copy link

paimoe commented Sep 15, 2023

Description

When using DebugUndefined to make a partial template, the filters are not kept if a variable is not passed to the template. Similar-ish to #1871 and other DebugUndefined issues.

Replication

>>> import jinja2
>>> jinja2.__version__
'3.1.2'
>>> env = jinja2.Environment(undefined=jinja2.DebugUndefined)
>>> template = env.from_string("{{ var|safe }}")
>>> template.render()
'{{ var }}'
>>> template.render(var="hello")
'hello'
>>> 

Expectation

I'm not sure 100% sure if this is the best way to do a partial template rendering, but was all I found on Stackoverflow and other places.

https://stackoverflow.com/questions/12994028/multiple-renders-of-jinja2-templates (old)

Environment:

  • Python version: 3.8.12
  • Jinja version: 3.1.2

Workaround

My current workaround is just a string replace like

base_template = base_template.replace(
        "var", "var | safe"
    )
@ThiefMaster
Copy link
Member

I'm pretty sure that your usecase is not what DebugUndefined is meant for - it's simply meant to be a way to quickly see the variable that's missing. Not to get something that's again to be used as a functional jinja template....

@davidism davidism closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants