Skip to content

Conversation

@riyaz489
Copy link

@riyaz489 riyaz489 commented Nov 9, 2023

Issue:
As compiled Jinja Blocks does not have info about parent template scopes like autoescape,
due to which it is ignoring those inherited properties.

Fix:
Fixed the compiler. We made blocks compilation volatile so that it will figure out the correct
property during rendering time.

Issue:
Ideally, the child template body should contain blocks as the first child. because only blocks in the
child template will be replaced with the blocks in the main template.
but whenever the developers write blocks inside other Scoped Nodes, the block is compiled as a part of scoped Node
code by the Jinja compiler. Once the child template is compiled, then the Jinja compiler complies all blocks separately
as well.
Due to this behaviour blocks were compiled multiple times. once when they are part of a scoped node's body and again
when all blocks are compiled. This behaviour leads to unexpected results

Fix:
Fixed Node Parser. So each node in the child template body is inspected to
identify the first block node and move it into the template body. (to avoid multiple parsing of blocks.)
These blocks will be seamlessly placed in the main template body.
Because outer scoped nodes of blocks do not make any scene for the child template as only data inside
blocks will be replaced in the main template.

Checklist:

  • [x ] Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • [x ] Add or update relevant docs, in the docs folder and in code.
  • [x ] Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • [x ] Add .. versionchanged:: entries in any relevant code docs.
  • [ x] Run pre-commit hooks and fix any issues.
  • [x ] Run pytest and tox, no tests failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants