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

Output finalize function issue #63

tzzt opened this issue Oct 2, 2011 · 3 comments · Fixed by #1080

Output finalize function issue #63

tzzt opened this issue Oct 2, 2011 · 3 comments · Fixed by #1080


Copy link

tzzt commented Oct 2, 2011

The finalize function seems to be executed on the whole template, not only on variables.

E.g. a function like
def fin(s): print s; return s
dumps the whole template file.

Copy link

jturmel commented Jul 3, 2013

Any input on this, we're running into the same thing?

We like to look at the variable expressions and modify them based on different criteria but returning the entire template makes this impossible.

Copy link

ntrepid8 commented Mar 29, 2014

I'm seeing this too. It seems like finalize should run only on expressions evaluated during render, but it runs when the template is constructed also.

Copy link

godsarmy commented Jan 20, 2016

is this fixed? i still see it in the latest version (2.8).

rom jinja2 import Environment, Template

context = {'k': 'v'}

template = """
{{ k }}

def fin(data):
    return 'replaced'

env = Environment(finalize=fin)

tpl = env.from_string(template, template_class=Template)

print tpl.render(**context)

It displayed 'replacedreplacedreplaced', we want this to be fixed as we need this feature very explicitly

@davidism davidism added this to the 2.11.0 milestone Oct 13, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet

Successfully merging a pull request may close this issue.

5 participants