使用CollectionType自定义表单的表单主题

我正在使用symfony,我渲染一个使用集合类型的表单。</ p>

< p>在我的config.yml中指定了一个全局表单主题。</ p>

例如这一个:</ p>

  twig:
debug:“ %kernel.debug%“
strict_variables:”%kernel.debug%“
form_themes:
  • 'foundation_5_layout.html.twig'
    </ code> </ pre>

    如果我进入 我的树枝模板是一个不同的形式主题,如... </ p>

      {%form_theme form'Form / bootstrap_3_layout.html.twig'%} 
    </ code> </ pre >

    这会影响我的所有其他表单元素,但不会影响具有Type CollectionType的表单元素。 它仍然使用config.yml中定义的主题</ p>

    如何解决此问题?</ p>
    </ div>

展开原文

原文

I am using symfony and I render a form which uses a collection type.

In my config.yml a global form theme is specified.

For example this one:

twig:
debug:            "%kernel.debug%"
strict_variables: "%kernel.debug%"
form_themes: 
    - 'foundation_5_layout.html.twig'

If I set in my twig template a different form theme like this...

{% form_theme form 'Form/bootstrap_3_layout.html.twig' %}

This has an effect on all of my other form elements but not on the one with the Type CollectionType. It still uses the theme defined in the config.yml

How can I solve this issue?

1个回答

Not really sure if this is what are you looking for but i don't use the config.yml for form themes i set them manually on each file and render everything manually based on what i want the form to look.

An example of how an entry field looks like ( the name in the form class is answer

{% block _suggest_question_manager_answer_entry_widget %}
    {% spaceless %}
        <div class="multiple-choice-container">
            <div class="row form-group">
                {{ form_label(form.value, null, {'label_attr': {'class': 'col-sm-2 control-label'} } ) }}
                <div class="col-md-12">
                    <div class="input-group">
                        <div class="input-group-addon">
                            <span class="glyphicon glyphicon-record" aria-hidden="true"></span>
                        </div>
                        {{ form_widget(form.value, {'attr': {'class': 'form-control'} } ) }}
                        {{ form_errors(form.value) }}
                        <div class="input-group-btn">
                            <button class="add-answer btn btn-default" aria-label="Add Choice">
                                <span class="glyphicon glyphicon glyphicon-plus" aria-hidden="true"></span>
                            </button>
                            <button class="remove-answer btn btn-default" aria-label="Remove Choice">
                                <span class="glyphicon glyphicon glyphicon-minus" aria-hidden="true"></span>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    {% endspaceless %}
{% endblock %}

How i render the prototype

<script id="answer-template" type="text/template">{{ form_widget(form.answer.vars.prototype) }}</script>

And this is how i load my themes ( it's just an example from a wip template didn't move the template file yet )

{% form_theme form _self %}

I choose my form theme manually each time and not using the global config one because at some point prob i had some problems and didn't stay to figure it out .. prob related to crud operations where i was getting double div wraps one from my own html in the prototype and second one from the form theme and that's why i render each field manually

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问