Sylius: How to reference your own twig template in a grid?

早过忘川 提交于 2020-01-25 06:48:09

问题


This is not a duplicate of e.g. Referencing a template in Twig / Symfony2 because creating bundles as applications is deprecated/not recommended anymore and therefore the answer is not applicable anymore. How do I reference my own template in a Sylius grid?

What I tried:

1.

                options:
                    template: "@App/Order/Grid/Field/channel.html.twig"

2.

                options:
                    template: ":Order/Grid/Field:channel.html.twig"

3.

                options:
                    template: "templates/Order/Grid/Field/channel.html.twig"

4.

                options:
                    template: "Order/Grid/Field/channel.html.twig"

(I tried some of these on the basis of the documentation: https://docs.sylius.com/en/1.6/components_and_bundles/bundles/SyliusGridBundle/field_types.html#twig-twig , https://docs.sylius.com/en/1.6/components_and_bundles/bundles/SyliusGridBundle/your_first_grid.html)

In all cases it says the template was not found. Any ideas?


回答1:


How do you create grid or customize them? For example, I am trying to customize Admin > Catalog > Options grid, so by this tutorial put these lines at the end of config/packages/_sylius.yaml file:

sylius_grid:
    grids:
        sylius_admin_product_option:
            fields:
                name:
                    type: twig
                    options:
                        template: "Grid/mytemplate.html.twig"

Secondly, I create folder "Order" in /templates, then "Grid" folder in "Order" dir, and then folder "Field" in "Grid" directory. There I create file "mytemplate.html.twig" with any content. Did you tried similar steps?



来源:https://stackoverflow.com/questions/59648295/sylius-how-to-reference-your-own-twig-template-in-a-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!