Is it meant to be possible to include blocks in partials? #4230
-
|
I have a site header partial, which I think it quite common. It looks like this: I include it in my On every page except one, I will be displaying the I tried the following: But the cartnav block still shows with its default content. If I get rid of the Am I missing something? Or do blocks just not work in partials? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
I have also encountered this problem. According to Nunjucks' template inheritance blocks are only supported in templates that Maybe, a workaround could be to replace the block with a conditional that checks for the current page's url or to set a flag in your frontmatter? That could look like this: <header>
<div class="nav-container">
<nav class="header-nav">
<a href="shop.html" class="shop-link">Shop</a>
<a href="gallery.html">Gallery</a>
<a href="/exhibitions">Exhibitions</a>
</nav>
{% if page.url == "/the/page/url" or includeCartNav %}
{# with `includeCartNav` being set in the page's frontmatter #}
<nav class="cart-nav">
<a href="cart.html">Cart (<span class="cart-item-count"></span>)</a>
</nav>
{% endif %}
</div>
</header>I hope that helps and let me know if you found a solution! |
Beta Was this translation helpful? Give feedback.
-
|
I think I „solved” this by putting a |
Beta Was this translation helpful? Give feedback.
I have also encountered this problem. According to Nunjucks' template inheritance blocks are only supported in templates that
extendan ancestor and lack support for your use case of using them in partials.Maybe, a workaround could be to replace the block with a conditional that checks for the current page's url or to set a flag in your frontmatter? That could look like this: