首页 > 解决方案 > 从模板中的扩展表中读取数据

问题描述

我有一个关于shopware 6 的问题。我为我的property_group 选项创建了一个额外的表,称为property_group_extension。所以我在我的主题中扩展了这张表:

class PropertyGroupExtension extends EntityExtension
{
    public function extendFields(FieldCollection $collection): void
    {
        $collection->add(
            new OneToOneAssociationField('property_group_extension', 'id', 'property_group_id', PropertyGroupExtensionDefinition::class, true)
        );
    }

    public function getDefinitionClass(): string
    {
        return PropertyGroupDefinition::class;
    }
}

但是如何在我的树枝模板中调用这个额外的 db-table property_group_extension(带有列test )?这不起作用:

properties.html.twig:
{% for group in page.product.sortedProperties %}
    {% block page_product_detail_properties_table_row %}
        <tr class="properties-row">
            {% block page_product_detail_properties_item_label %}
                <th class="properties-label">
                    {{ group.test }} - {# <= HOW CAN I INSERT HERE MY TEST COLUMN??? #}
                    {{ group.translated.name|e }}:
                </th>
            {% endblock %}
            {% block page_product_detail_properties_item_value %}
                <td class="properties-value">
                    {% apply spaceless %}
                        {% for option in group.options %}
                            {% set i = ( i | default(0) ) + 1 %}
                            <span>{% if i > 1 %}, {% endif %}{{ option.translated.name|e }}</span>
                        {% endfor %}
                    {% endapply %}
                </td>
            {% endblock %}
        </tr>
    {% endblock %}
{% endfor %}

标签: twigshopware

解决方案


I believe, the data does not automatically populate to the data structures in the twig by adding an extension.

You usually would hook into an even that is triggered for the page you want to access the data in.

Next you add an extension to the result so it is accessible in the twig template.


推荐阅读