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

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100