question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Block assignment scope is different than inline assignment

See original GitHub issue

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!' %}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
arkafoncommented, 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 %}
1reaction
mitsuhikocommented, Dec 31, 2016

Changed in 45b59b522a542c21611214b352df049a3b6dbcb4

Read more comments on GitHub >

github_iconTop Results From Across the Web

Common Scope Block Tasks - MATLAB & Simulink - MathWorks
Step-by-step procedures of common scope tasks, including logging data, sharing scope images, and display manipulation.
Read more >
Variable declaration, intitialiation, assignment, and scope
Essentially this question is more about the hows and why's than the results. I know that scope is based on where the variable...
Read more >
Demystifying JavaScript Variable Scope and Hoisting - SitePoint
This article will explain how JavaScript's scoping system works. You'll learn about the different ways to declare variables, the differences ...
Read more >
Working with Blocks - Apple Developer
Blocks Can Simplify Concurrent Tasks. A block represents a distinct unit of work, combining executable code with optional state captured from ...
Read more >
using statement - C# Reference | Microsoft Learn
The using statement causes the object itself to go out of scope as soon as Dispose is called. Within the using block, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found