简体   繁体   English

如何在其他树枝+模式对话框Symfony2中渲染视图

[英]How to render a view inside of other twig + Modal Dialog Symfony2

Today I wanna a show a modal dialog with a form 今天我想展示一个带有形式的模态对话框

This is my code of main: 这是我的主要代码:

<button class="btn btn-primary btn-lg btn-new" data-toggle="modal" data-target="#agregarPunto">
          Nueva Ronda
</button>
<div  style="display: none;"  class="modal fade" id="agregarPunto" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"  aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Agregar ronda</h4>
            </div>
            <div class="modal-body">
                 {% embed "controlidMembersBundle:Members:newRonda.html.twig" %}
                 {% endembed %}
             </div>
             <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                <button type="button" class="btn btn-primary">Crear ronda</button>
             </div>
         </div>
     </div>
 </div>

This is the code of my view that I wanna embed 这是我想嵌入的观点代码

{% block nueva_ronda -%}
   <h1>Nueva ronda</h1>
   {{ form(form) }}
   <ul class="record_actions"></ul>
{% endblock %}

The trouble is when I click on the button, because I get the following error: 问题是当我单击按钮时,因为出现以下错误:

Variable "form" does not exist in   /var/www/html/controlid/src/controlid/Bundle/MembersBundle/Resources/views/Members/newRo nda.html.twig at line 5

This mistake is obviusly, because I don't know how to call the controller to render the form. 这个错误很明显,因为我不知道如何调用控制器来呈现表单。

This is the action on symfony that should rendered the form 这是应该在symfony上执行的动作,形式如下

/*
 * @Route("/ronda/crear", name="members_ronda_new")
 * @Method("GET")
 * @Template()
 */
public function newRondaAction()
{
    $entity = new Ronda();
    $form   = $this->createRondaForm($entity);

    return array(
        'entity' => $entity,
        'form'   => $form->createView(),
    );
}

How to embed code inside of my modal-dialog to render the form? 如何在模态对话框中嵌入代码以呈现表单?

I think what you want is to embed the action into your twig template. 我认为您想要的是将动作嵌入到树枝模板中。 Try this: 尝试这个:

<div class="modal-body">
    {{ render(controller('controlidMembersBundle:Members:newRonda')) }}
</div>

Put this line at the top of your template: 将此行放在模板的顶部:

{%- use 'controlidMembersBundle:Members:newRonda.html.twig' -%}

JFYI you should start the bundle name with an upper case letter (Symfony standard conventions). JFYI,您应使用大写字母(Symfony标准约定)开头捆绑软件名称。

Then instead of embedding simply render the block with: 然后,而不是嵌入,只需使用以下命令渲染块:

{{ block('nueva_ronda') }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM