Code Monkey home page Code Monkey logo

Comments (4)

seehat avatar seehat commented on June 26, 2024

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?

from kirby-twig.

denisbertrandbe avatar denisbertrandbe commented on June 26, 2024

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' => [],

from kirby-twig.

denisbertrandbe avatar denisbertrandbe commented on June 26, 2024

I have found the solution. Cleaning some content text files containing old references to a field solved the problem !
Thank you.

from kirby-twig.

seehat avatar seehat commented on June 26, 2024

Ah good that you found the solution. Thanks for looking into it on your own. I was busy the weekend.

from kirby-twig.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.