Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render all fields except the submit in symfony 2.3

I'm overriding Skeleton templates of SensioGeneratorBundle as describred in:

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

So until here is everything fine.

In one of the templates of SensioGeneratorBundle I have:

# 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 %}

This works, but {{ form(form) }} is rendering the submit button, and I want to render the submit button in the record_actions.html.twig.twig.

So my question is: How to render a form without render the submit button? Remembering that i'm trying to do this in the skeleton template, in this moment I don't have the fiels of the form to iterate over it.

Thanks!

like image 758
murilolobato Avatar asked Mar 25 '26 04:03

murilolobato


1 Answers

The solution for this problem is as follows:

# 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 %}

And inside 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>
like image 165
murilolobato Avatar answered Mar 26 '26 23:03

murilolobato



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!