douzuo5504 2016-09-12 14:56
浏览 58

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

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条回答 默认 最新

  • doulan8846 2016-09-12 17:46
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?