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

Block assignment scope is different than inline assignment #596

Closed
mtrstudio opened this issue Jun 26, 2016 · 5 comments
Closed

Block assignment scope is different than inline assignment #596

mtrstudio opened this issue Jun 26, 2016 · 5 comments
Labels

Comments

@mtrstudio
Copy link

mtrstudio commented Jun 26, 2016

I want to set a variable in a child template that will be rendered in the parent template. If I use block assignment, nothing is rendered. If I use inline assignment, it works as expected. I am using Jinja 2.8 with Python 2.

base.html:

{{ content }}

bad.html with block assignment, nothing rendered:

{% extends 'base.html' %}
{% set content %}
Hello, World!
{% endset %}

good.html, renders correctly:

{% extends 'base.html' %}
{% set content = 'Hello, World!' %}
@davidism davidism changed the title Block Assignment is not working! Block assignment scope is different than inline assignment Jun 27, 2016
@davidism davidism added the bug label Jun 27, 2016
@arkafon
Copy link

arkafon commented Sep 27, 2016

Got this problem too. Simple test:

{% extends "..." %}
...
{% set aaa = 'test' %}
{% set bbb %}
    <a href="/">bar</a>
{% endset %}
...
{% block some_block %}
 {{ aaa }} {# renders 'test' #}
 {{ bbb }} {# renders empty string #}
{% endblock %}

@charleschen
Copy link

I'm getting the same inconsistent behavior with the 'with' statment:

{% with %}
{% set something = 'werd' %}
{% set something_block %}
werd werd werd
{% endset %}
{% endwith %}
...
{{ something }} {# renders empty string #}
{{ something_block }} {# renders 'werd werd werd' #}

these bugs are probably related?

@mitsuhiko
Copy link
Contributor

The with statement is not supposed to work that way, so that's intentional. I cannot reproduce the set issue however independently of this in master.

@mitsuhiko
Copy link
Contributor

Nevermind, I see what this issue is about.

@mitsuhiko
Copy link
Contributor

Changed in 45b59b5

@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.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants