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.

Plan to implement {{block.super}}

See original GitHub issue

Hello, thanks for your hard works! currently I’m using nunjucks in our frontend project(mock server with express), but I have a plan to migrate to liquidjs instead, because our Backend is also using liquid, some of their syntax differencies bother me a lot because each time I have to manually adjust nunjucks templates to standard liquid syntax before sending them to backend developers, I have searched a lot and finally found liquidjs, really amazing, but I really miss the {{block.super}} syntax, since we have already supported “block”, I would like to know do we have some plan to implement it as well? It would be a huge benefit and I think some others might also have the same question as me 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rdmurphycommented, May 22, 2020

Hello @harttle! 👋 I was hunting around to see if this feature had already been mentioned and ended up here.

I do wonder if this is something that may be reconsidered (AFAICT it still does not exist in Ruby Liquid). However, I do think the value of having something like {{ block.super }} may have been a little muddled back in 2017.

As it exists in Django, {{ block.super }} is a way to tap into the contents of a block as it exists in a parent layout without overriding it, but it does not attempt to mix the parent or child scopes. As explained here in Django docs (emphasis mine):

If you need to get the content of the block from the parent template, the {{ block.super }} variable will do the trick. This is useful if you want to add to the contents of a parent block instead of completely overriding it. Data inserted using {{ block.super }} will not be automatically escaped (see the next section), since it was already escaped, if necessary, in the parent template.

(This also exists in the Jinja2-inspired Nunjucks as the {{ super() }} function.)

What I’ve commonly used this to do is append or prepend markup that has been defined in a parent layout’s block without overriding it. A good example of this with CSS linking:

Parent layout: base.html

{% block css %}
<link href="base.css" rel="stylesheet">
{% endblock css %}

Child page: index.html

{% layout "base.html" %}

{% block css %}
{{ block.super }}
<link href="extra.css" rel="stylesheet">
{% endblock css %}

Output

<link href="base.css" rel="stylesheet">
<link href="extra.css" rel="stylesheet">

What’s nice about this is you can define some defaults or base values in a block that the inheriting template can choose to overwrite or add to as needed. As provided in the two scenarios I am familiar with (Django and Nunjucks) there is never the intention that the parent and child pages’ scopes combine or interact in any way — either the as-rendered contents of the parent page’s block is rendered as-is where {{ block.super }} was called, or it’s overwritten by the contents of the child page’s contents of the block.

I believe this is can be very helpful for defining blocks in a parent layout with smart defaults that a child page can augment instead of completely overwrite (or as it often happens, content that appeared in the parent’s block gets copy-pasted to the child page’s block because it needed the exact same content + an extra line on the end).

1reaction
harttlecommented, Jan 23, 2021

Now supported on @9.20.0, thank you guys.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The potential of implementing superblocks for multifunctional ...
The Barcelona superblock has been proposed as a sustainable urban neighbourhood transformation strategy in cities.
Read more >
what is the purpose of {{block.super}} in django template?
Can anybody tell me what is block super in the case of django template language? ... So lets create a block in example.html...
Read more >
Blocks, Superblocks and the Making of Cities
Superblocks were part of the modern architecture movement, but they were even more an attempt to marry city planning with the automobile.
Read more >
What are Super Blocks - The Design Response
“ The plan is based around the idea of superilles (superblocks) – mini neighbourhoods around which traffic will flow, and in which spaces...
Read more >
Barcelona's superblocks are a new model for “post-car” urban ...
If the plan can survive politics, it can demonstrate how to create tight-knit urban communities.
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