我想根据订单中的某些产品,在管理视图中向订单网格的通道显示添加一些内容。在示例中,我需要一种将记录的数据注入到树枝模板中的方法。
无法解决。网格看起来像这样:
sylius_grid:
grids:
sylius_admin_order:
driver:
name: doctrine/orm
options:
class: "%sylius.model.order.class%"
repository:
method: createListQueryBuilder
sorting:
number: desc
fields:
...
channel:
type: twig
label: sylius.ui.channel
sortable: channel.code
options:
template: "@SyliusAdmin/Order/Grid/Field/channel.html.twig"
[我看到他们在其他列中在选项中添加了vars:在这样的示例中:
options:
template: ...
vars:
labels: "@SyliusAdmin/Order/Label/State"
但是如何处理自身,我的意思是处理记录中的其余数据?我需要这样的东西:
options:
template: "@SyliusAdmin/Order/Grid/Field/channel.html.twig"
vars:
order: self
有人知道这样做的方法吗?
Sylius-Grid在渲染时将options
变量传递到模板中。例如,标准label
参数的外观:
@ SyliusAdmin / config / grids / order.yml中的网格定义:
...
paymentState:
type: twig
label: sylius.ui.payment_state
sortable: ~
options:
template: "@SyliusUi/Grid/Field/state.html.twig"
vars:
labels:
...
@@ SyliusUi / Grid / Field / label.html.twig:
{% set value = 'sylius.ui.' ~ data %}
{% if options.vars.labels is defined %}
{% include [(options.vars.labels ~ '/' ~ data ~ '.html.twig'), '@SyliusUi/Label/_default.html.twig'] with {'value': value} %}
{% else %}
{% include '@SyliusUi/Label/_default.html.twig' with {'value': value} %}
{% endif %}
在此示例中,传递的变量labels
在Grid Yaml定义中传递,可在Twig options.vars.labels
变量中使用。
您可能需要使用EDIT:如果要访问模板中的实体对象的其他属性,而不仅仅是本例中的
channels
,则将其添加到网格字段定义根目录:
channel: type: twig label: sylius.ui.channel path: .
php bin/console cache:clear
刷新Twig缓存。在https://docs.sylius.com/en/1.6/components_and_bundles/bundles/SyliusGridBundle/field_types.html#twig-twig中了解有关此内容的更多信息>