Closed denisbertrandbe closed 2 years ago
This should work, can you give me more context and post the whole text.twig file and your twig config? Are you on the latest version?
I'm on the last version : 4.1.7. I made a plugin which define a macro to handle a kind of template suggestion for my blocks :
{% macro ui_blocks(page) %}
{% set blueprint = page.blueprint().name %}
{% for field in page.content().keys() %}
{% include [
'@snippets/blocks/' ~ blueprint ~ '/' ~ field ~ '.twig',
'@snippets/blocks/' ~ field ~ '.twig',
'@snippets/blocks/' ~ blueprint ~ '/default.twig',
'@snippets/blocks/default.twig'
] %}
{% endfor %}
{% endmacro %}
from my page template I call this macro :
{{- ui_blocks(page) -}}
I have a builder block (layout field) ('@snippets/blocks/builder.twig') which also use a template suggestion system :
{% set blueprint = page.blueprint().name %}
{% for layout in page.content.builder.toLayouts() %}
<section>
{% set columns = layout.columns() %}
{% for column in columns %}
<div class="{{ column.span() }}">
{% for block in column.blocks() %}
{% set type = block.type() %}
{% include [
'@snippets/blocks/' ~ blueprint ~ '/' ~ type ~ '.twig',
'@snippets/blocks/' ~ type ~ '.twig',
'@snippets/blocks/' ~ blueprint ~ '/default.twig',
'@snippets/blocks/default.twig'
] with { 'foo': 'bar' } %}
{% endfor %}
</div>
{% endfor %}
</section>
{% endfor %}
So if I add a text block it calls
@snippets/blocks/text.twig
which contains
<div class="prose">
{{ foo }}
{{ page.content.text.kirbytext | raw }}
</div>
My twig configuration is the following :
'amteich.twig.env.functions' => [
// Plugin db-helper
'isHtmxRequest' => 'isHtmxRequest',
'db' => 'db',
'meta' => 'meta',
// Laravel mix
'mix' => 'mix',
],
'amteich.twig.env.filters' => [],
'amteich.twig.env.tests' => [],
I have found the solution. Cleaning some content text files containing old references to a field solved the problem ! Thank you.
Ah good that you found the solution. Thanks for looking into it on your own. I was busy the weekend.
Hello,
Vars sent to included template seems to not be sent or included :
{% include '@snippets/blocks/text.twig' with { 'foo':'bar'} %}
When I do a
{{ dump(foo) }}
in @snippets/blocks/text.twig, I have an error :Maybe I do something wrong but it doesen't seems
Thank you