twig - 从模板中的扩展表中读取数据
问题描述
我有一个关于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 %}
解决方案
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.
推荐阅读
- javascript - 如何在 vuejs 中获取特定的对象值?
- javascript - 在 const = require 中显示文件结构的正确方法?
- python-2.7 - 如何在 python 2.7 中执行我的程序逻辑之前响应 HTTP 请求
- c - Gtk-CRITICAL **: 16:04:21.737: gtk_box_pack: 断言 'GTK_IS_WIDGET (child)' 失败
- yocto - 如何将 ldd 实用程序添加到 bitbake 图像
- javascript - 如何将具有特定键、深度键的 JSON 对象中的所有值放入数组中
- php - 返回 JSON 响应而不是 401 Blade 文件
- nlog - 未找到 NLog MessageBox 目标
- excel-formula - excel 修剪功能正在删除文本中间的空格 - 这是出乎意料的(?)
- api - Chrome DevTools 在执行之前批准网络请求