- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好的,所以我有一个包含 2 个选项的选择表
$builder->add('type', 'choice', array(
'label' => 'User type',
'choices' => array('1' => 'Customer', '2' => 'Supplier'),
'expanded' => true,
'multiple' => false,
'required' => false,
));
{{ form_widget(form.type/choice_1/) }}
some html stuf
{{ form_widget(form.type/choice_2/) }}
最佳答案
您需要将模板添加到表单中。这是文档:
http://symfony.com/doc/current/cookbook/form/form_customization.html
在这里,您有多个示例:
https://github.com/phiamo/MopaBootstrapBundle/blob/master/Resources/views/Form/fields.html.twig
此字段适合您:
{% block choice_widget_expanded %}
{% spaceless %}
<div {{ block('widget_container_attributes') }}>
{% for child in form %}
<label class="{{ (multiple ? 'checkbox' : 'radio') ~ (widget_type ? ' ' ~ widget_type : '') ~ (inline is defined and inline ? ' inline' : '') }}">
{{ form_widget(child, {'attr': {'class': attr.widget_class|default('')}}) }}
{{ child.vars.label|trans({}, translation_domain) }}
</label>
{% endfor %}
</div>
{% endspaceless %}
{% endblock choice_widget_expanded %}
{{ form_widget(child, {'attr': {'class': attr.widget_class|default('')}}) }}
独自的 :)
YourBundle/Resources/Form/fields.html.twig
{% form_theme form 'AcmeDemoBundle:Form:fields.html.twig' %}
关于forms - Symfony2 选择形式 split 成 Twig ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12507957/
Twig 使用 {{ }}、{% %}、{# #} 分隔符。 但是如何在 Twig 模板中显示 {{ }} 呢?我不是在谈论 HTML 转义。 我问这个问题是因为我想在我的 Twig 模板中包含一个
为了转换我的法语 html 口音,我尝试通过在 Twig 中执行此操作来更改编码: {{ ddf.description | convert_encoding('UTF-8', 'HTML-ENTIT
我有一个带有输出元素的 .twig 文件的循环。 我需要为每个元素增加一个值。我知道如何在 PHP 中执行此操作,但不清楚如何使用 twig 文档执行此操作。我真的不能在 Controller 中做到
我有一个 xxx.html.twig 文件,它显示一个页面,但是当我想用不同的数据刷新页面并用新数据更新它时,我有一个选择和一个提交按钮。问题是我不知道如何在 Controller 中调用一个 Act
我需要使用 Liquid 来创建模板,但可能只能访问 Twig 模板语言。这两种语言基本上是相同的东西,还是语言上存在差异,导致很难使用 Twig 来替代 Liquid? 最佳答案 Twig 和 Li
number rounding 的 Twig 文档谈论四舍五入小数,但我有一个案例,我想将 19,995 这样的数字四舍五入到 20,000。是否有一种巧妙的方法可以四舍五入到最接近的千位? 最佳答案
我在 2.7 和 3.1 版本中都有 Symfony 项目。 PhpStorm 启用了 Symfony 插件和 Twig 支持插件。 当我在 Symfony 2.7 版本的 PhpStorm 中工作时
我已升级到新版本的 twig/twig 3.x.x。从 twig 版本 3.0 开始,Twig_Extension 已被弃用。所以我接下来要讨论“whiteoctober/breadcrumbs-bu
我在 Twig 中经常有类似的样板代码: {% if (somelongcond) %} {% endif %} Some long content {% if (somelongcond)
我想在我自己的插件中覆盖来自插件的 Twig 模板的 block 。我过去曾覆盖过 native 商店软件模板,但我在使用插件模板时遇到了麻烦。 我正在尝试调整的插件是 FroshProductCom
我用带 Twig 的silex; 我创建自定义 form_div_layout 并将其放在 webroot 中(例如) 我这样注册 TwigService 提供者 $app->register
我不太明白 Twig 中的属性函数是如何工作的。有人可以帮我举个例子吗? 我在 SQL 中有一个名为动态的字段。我可以是例如“field27”,但我不知道号码,号码保存在 radio.id 中。我想做
我想知道是否有一种方法可以在 TWIG 中创建多语句 示例:两个单独的语句... {% set foo:bar %} {% set baz:qux %} 合并成一个语句 {% set foo:
我正在尝试使用 Twig i18n 扩展。 据我所知,我需要的文件在这里: https://github.com/fabpot/Twig-extensions/blob/master/lib/Twig
我正在使用 patternlab 的节点版本用 Twig 作为模板引擎。我正在使用 twig,因为我的代码库是用 twig 编写的 - 所以使用 mustache 不是一个选项。 我简单地尝试包含一个
我有以下代码: {% set pageDescription = item.description|length > 197 ? item.description|striptags|trim|sli
我有以下 Twig 代码: {% for likeditem in user.getItemLikes() %} //iterate over each liked items here {%
反正有没有像这样在 Twig 中重复一个块: {% block title %}{% endblock %} | MyBusiness 为了只声明两个块一次?像那样: {% block title
编辑:2016年12月3日 想学习如何向 Twig 添加自定义扩展(过滤器)吗?请参阅this answer的lxg 您是否只需要找到与ucword等效的嫩枝?请参阅this answer的Javie
我有一个简单的浮点数组。我需要将它显示为逗号分隔的字符串。 {{ arr|join(', ') }} 由于过度的微不足道的准确性,这是一个糟糕的解决方案。 {% for val in arr %}
我是一名优秀的程序员,十分优秀!