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.

Overriding a block within an include

See original GitHub issue

base.html

{% include 'partial.html' %}

partial.html

{% block contents %}
partial.html
{% endblock %}

extension.html

{% extends 'base.html' %}
{% block contents %}
extension.html
{% endblock %}

Nunjucks 1.3.4 actual:

partial.html

Expected (?):

extension.html

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
canducommented, Feb 20, 2021

This reminds me of React’s children or Vue’s slot mechanism, which in turn would suggest a syntax like:

{% include 'component' %}
  {% block main %}
    <!-- block content here -->
  {% endblock %}
{% endinclude %}

which avoids the name collision issue by scoping blocks within the context of the included template. (I don’t know how parser internals work here, though, so no idea how feasible this would be - and at some point, you might just be better off using SSR support in React / Vue to perform static site generation, heh.)

1reaction
carljmcommented, Oct 29, 2015

It doesn’t relate to #539, IMO.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overriding blocks within included Twig templates
I found a solution. Use the block() function to get the child's block content and pass it to header.html.twig as a variable in...
Read more >
Conditional to override a block - Craft CMS Stack Exchange
I have a situation on a category page where I am wanting to override a block in the document this one is extending,...
Read more >
How to override templates - Django documentation
Overriding from the project's templates directory¶ ... First, we'll explore overriding templates by creating replacement templates in your project's templates ...
Read more >
Overriding blocks in mod-circulation - FOLIO Wiki
Override functionality allows the user to perform an action that should be otherwise blocked. Currently, there's only one type of check-out override -...
Read more >
Base Templates and Blocks - Hugo
The block keyword allows you to define the outer shell of your pages' one or more master template(s) and then fill in or...
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