根据字段的值更改奏鸣曲管理包中的行颜色
change row color in sonata admin bundle dependent on a value of a field
我有 sonata 管理包,但不知道如何根据表单模板中的字段值更改样式。
例如场地难度...难度值越高,记录行应该越红...
我该怎么做?我花了几个小时来理解奏鸣曲中的树枝模板,但我越读这个模板,我就越困惑。
模板中存在块调用,无法弄清楚此调用的来源或来源。
我将 symfony 2 与 Sonata Admin Bundle 一起使用。
谢谢
制作您自己的模板,扩展 SonataAdminBundle:CRUD:base_edit.html.twig 并覆盖您的管理员 class 的 $templates
属性 或将其传递给您的管理员像这样的服务声明:
librinfo_crm.admin.organism:
class: Librinfo\CRMBundle\Admin\OrganismAdmin
arguments: [~, Librinfo\CRMBundle\Entity\Organism, LibrinfoCRMBundle:OrganismAdmin]
tags:
- name: sonata.admin
manager_type: orm
group: Customers Relationship Management
label: librinfo.crm.organism_admin.label
label_translator_strategy: blast_core.label.strategy.librinfo
calls:
- [ setTemplate, [edit, LibrinfoCRMBundle:OrganismAdmin:edit.html.twig]] #set a custom edit template
- [ setTemplate, [show, LibrinfoCRMBundle:OrganismAdmin:show.html.twig]] #sets a custom show template
您的自定义模板需要覆盖默认奏鸣曲模板,例如:
{% extends 'SonataAdminBundle:CRUD:base_edit.html.twig' %}
{% block form %}
{# your custom code #}
{% endblock %}
如果您不知道要扩展哪个块或哪个模板,请告诉我您想要自定义的视图(列出、编辑、显示),但可能是全部。
然后检索您想要的字段或任何您可以使用
{% dump %}
将模板的所有变量转储到分析器中或
{% dump(myVar) %}
转储特定变量
编辑
base_template
是从包含模板名称的控制器传递的变量。
If you look closely, all of these templates ultimately extend the
base_template variable that’s passed from the controller. This
variable will always take the value of one of the above mentioned
global templates, and this is how changes made to those files affect
all the SonataAdminBundle interface.
如果转储 base_template
变量,您将知道扩展了哪个模板。
对于 parentForm
块,请看上面:
{% use 'SonataAdminBundle:CRUD:base_edit_form.html.twig' with form as parentForm %}
此行导入 SonataAdminBundle:CRUD:base_edit_form.html.twig form
块别名为 parentForm
.
所以 {{ block('parentForm') }}
是从 SonataAdminBundle:CRUD:base_edit_form.html.twig.
渲染 form
块的调用
我有 sonata 管理包,但不知道如何根据表单模板中的字段值更改样式。
例如场地难度...难度值越高,记录行应该越红...
我该怎么做?我花了几个小时来理解奏鸣曲中的树枝模板,但我越读这个模板,我就越困惑。
模板中存在块调用,无法弄清楚此调用的来源或来源。
我将 symfony 2 与 Sonata Admin Bundle 一起使用。
谢谢
制作您自己的模板,扩展 SonataAdminBundle:CRUD:base_edit.html.twig 并覆盖您的管理员 class 的 $templates
属性 或将其传递给您的管理员像这样的服务声明:
librinfo_crm.admin.organism:
class: Librinfo\CRMBundle\Admin\OrganismAdmin
arguments: [~, Librinfo\CRMBundle\Entity\Organism, LibrinfoCRMBundle:OrganismAdmin]
tags:
- name: sonata.admin
manager_type: orm
group: Customers Relationship Management
label: librinfo.crm.organism_admin.label
label_translator_strategy: blast_core.label.strategy.librinfo
calls:
- [ setTemplate, [edit, LibrinfoCRMBundle:OrganismAdmin:edit.html.twig]] #set a custom edit template
- [ setTemplate, [show, LibrinfoCRMBundle:OrganismAdmin:show.html.twig]] #sets a custom show template
您的自定义模板需要覆盖默认奏鸣曲模板,例如:
{% extends 'SonataAdminBundle:CRUD:base_edit.html.twig' %}
{% block form %}
{# your custom code #}
{% endblock %}
如果您不知道要扩展哪个块或哪个模板,请告诉我您想要自定义的视图(列出、编辑、显示),但可能是全部。
然后检索您想要的字段或任何您可以使用
{% dump %}
将模板的所有变量转储到分析器中或
{% dump(myVar) %}
转储特定变量
编辑
base_template
是从包含模板名称的控制器传递的变量。
If you look closely, all of these templates ultimately extend the base_template variable that’s passed from the controller. This variable will always take the value of one of the above mentioned global templates, and this is how changes made to those files affect all the SonataAdminBundle interface.
如果转储 base_template
变量,您将知道扩展了哪个模板。
对于 parentForm
块,请看上面:
{% use 'SonataAdminBundle:CRUD:base_edit_form.html.twig' with form as parentForm %}
此行导入 SonataAdminBundle:CRUD:base_edit_form.html.twig form
块别名为 parentForm
.
所以 {{ block('parentForm') }}
是从 SonataAdminBundle:CRUD:base_edit_form.html.twig.
form
块的调用