【问题标题】:Render all fields except the submit in symfony 2.3在 symfony 2.3 中呈现除提交之外的所有字段
【发布时间】:2013-09-03 14:37:25
【问题描述】:

我正在覆盖 SensioGeneratorBundle 的骨架模板,如下所述:

http://symfony.com/doc/current/bundles/SensioGeneratorBundle/index.html#overriding-skeleton-templates

所以直到这里一切都很好。

在我拥有的 SensioGeneratorBundle 模板之一中:

# app/resources/SensioGeneratorBundle/skeleton/crud/views/new.html.twig.twig
{% block body %}

{{ "{% block page_title 'Incluir " ~ entity ~ "'%}" }}

{{ "{% block body -%}" }}

    {{ '{{ form(form) }}' }}

    {% set hide_edit, hide_delete = true, true %}
    {% include 'crud/views/others/record_actions.html.twig.twig' %}
{{ "{% endblock %}" }}
{% endblock body %}

这可行,但 {{ form(form) }} 正在呈现提交按钮,我想在 record_actions.html.twig.twig 中呈现提交按钮。

所以我的问题是:如何在不渲染提交按钮的情况下渲染表单?记住我正在尝试在骨架模板中执行此操作,此时我没有表单的字段来迭代它。

谢谢!

【问题讨论】:

    标签: twig symfony-forms symfony-2.3


    【解决方案1】:

    这个问题的解决方法如下:

    # app/resources/SensioGeneratorBundle/skeleton/crud/views/new.html.twig
    {% block body %}
    
    {{ "{% block page_title 'Incluir " ~ entity ~ "'%}" }}
    
    {{ "{% block body -%}" }}
    {{ "    {{ form_start(child) }}" }}
    {{ "    {% for child in form %}" }}
    {{ "        {% if child.vars.name != 'submit' %}" }}
    {{ "            {{ form_row(child) }}" }}
    {{ "        {% endif %}" }}
    {{ "    {% endfor %}" }}
    
    {% set hide_edit, hide_delete = true, true %}
    {% include 'crud/views/others/record_actions.html.twig.twig' %}
    
    {{ "{% endblock %}" }}
    {% endblock body %}
    

    record_actions.html.twig.twig里面

    # app/resources/SensioGeneratorBundle/skeleton/crud/views/record_actions.html.twig
    {{ "        {{ form_row(form.submit) }}" }}
    {{ "    {{ form_end(form) }}" }}
    <ul class="record_actions">
        <li>
            <a href="{{ "{{ path('" ~ route_name_prefix ~ "') }}" }}">
                Back to the list
            </a>
        </li>
    {% if ('edit' in actions) and (not hide_edit) %}
        <li>
            <a href="{{ "{{ path('" ~ route_name_prefix ~ "_edit', { 'id': entity.id }) }}" }}">
                Edit
            </a>
        </li>
    {% endif %}
    {% if ('delete' in actions) and (not hide_delete) %}
        <li>
            <form action="{{ "{{ path('" ~ route_name_prefix ~ "_delete', { 'id': entity.id }) }}" }}" method="post">
                <input type="hidden" name="_method" value="DELETE" />
                {{ '{{ form_widget(delete_form) }}' }}
                <button type="submit">Delete</button>
            </form>
        </li>
    {% endif %}
    </ul>
    

    【讨论】:

      猜你喜欢
      • 2013-04-02
      • 1970-01-01
      • 2019-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多