marello icon indicating copy to clipboard operation
marello copied to clipboard

Allow extending dataBlocks in twig templates

Open clicktrend opened this issue 4 years ago • 0 comments

For some reason it's very useful to allow extending dataBlocks in twig templates. For instance prepend to this set

{% set data = {
    'dataBlocks': dataBlocks,
} %}

this code

{% if data is defined and data.dataBlocks is defined %}
    {% set dataBlocks = dataBlocks|merge(data.dataBlocks) %}
{% endif %}

{% set data = {
    'dataBlocks': dataBlocks,
} %}

Then you can create your own twig template like this

{% extends '@!MarelloProduct/Product/view.html.twig' %}

{% block content_data %}
    {% set customBlock %}
        <div class="widget-content">
            Custom Block
        </div>
    {% endset %}
    {% set dataBlocks = [{
        'title' : 'Custom Block'|trans,
        'subblocks': [{
            'title' : null,
            'useSpan': false,
            'data' : [
                customBlock
            ]
        }]
    }] %}

    {% set data = {
        'dataBlocks': dataBlocks,
    } %}

    {{ parent() }}
{% endblock %}

clicktrend avatar Nov 17 '20 07:11 clicktrend