[英]Theming on a collection form in SF2
Is it possible to customize the widget of a specific collection in a Symfony 2 Form ? 是否可以在Symfony 2 Form中自定义特定集合的小部件?
I saw this block in the default theme : 我在默认主题中看到了此块:
{% block collection_widget -%}
{% if prototype is defined %}
{%- set attr = attr|merge({'data-prototype': form_row(prototype) }) -%}
{% endif %}
{{- block('form_widget') -}}
{%- endblock collection_widget %}
But I dont want to override this widget for all collections, just for one specific collection. 但我不希望重写此插件的所有收藏,只为一个特定集合。
Here is the declaration of my collection : 这是我收藏的声明:
$builder->add(
$builder->create('photos', 'collection', [
'type' => 'photo',
'allow_add' => true,
])->setData($photosValues)
);
Is there a way to do something like this ? 有没有办法做这样的事情?
{% block collection_photo_widget -%}
Here my HTML for my photo collection
{%- endblock collection_widget %}
Regards 问候
To find the right block name, go to profiler > forms > {your form} > {your collection field} > view variables
要找到正确的块名称,请转至
profiler > forms > {your form} > {your collection field} > view variables
youll see a key there: "unique_block_prefix"
您会在那里看到一个键:
"unique_block_prefix"
this is the name of your block to edit the whole collection widget, you should add _widget to the block name to go deeper 这是您用来编辑整个集合窗口小部件的块的名称,您应该在块名称上添加_widget来进行更深入的介绍
$builder->add(
$builder->create('photos', 'collection', [
'type' => 'photo',
'allow_add' => true,
'attr' => array('class'=>'myCSSClassName'),
])->setData($photosValues)
);
No need to touch the core system 无需接触核心系统
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.