Php Simfony2细枝:仅渲染模板的单个部分

Php Simfony2细枝:仅渲染模板的单个部分,php,symfony,twig,Php,Symfony,Twig,我有一个主页,动态加载一堆“帖子”(类似于facebook墙) 有跟踪帖子的选项,但当有人单击“跟踪”按钮时,该按钮有一个跟踪人的计数器,我需要重新加载所有主页以更新此值。如何仅更新与帖子对应的部分?实际上,这篇文章位于一个extern hmtl.twig文件中,我从主页代码中呈现: <div class="row"> <div class="col-md-6"> {% for sueno in suenos %}

我有一个主页,动态加载一堆“帖子”(类似于facebook墙)

有跟踪帖子的选项,但当有人单击“跟踪”按钮时,该按钮有一个跟踪人的计数器,我需要重新加载所有主页以更新此值。如何仅更新与帖子对应的部分?实际上,这篇文章位于一个extern hmtl.twig文件中,我从主页代码中呈现:

<div class="row">
        <div class="col-md-6">
         {% for sueno in suenos %}
            {% if loop.index0 is even %}
                {{ render(controller('SuenoBundle:Default:suenoFrontend', { 'sueno': sueno } )) }}
            {% endif %}
         {% endfor %}
       </div><!--/col-md-6-->
这是post html文件:

                <h4 class="text-center nombre-usuario">{{ sueno.usuario.nombre ~ ' ' ~ sueno.usuario.apellido }}</h4>   
                  {% if sueno.necesitaAyuda == 1 %}
                    <p class="text-center texto-sueno"><img src="{{ asset('bundles/estructura/images/SOS.png') }}" width="25" height="25" alt="SOS" /></p>       
                  {% endif %}                    
                  {% if sueno.rol == 'foto' %}
                          <a href="#" data-toggle="modal" data-target="#imageModal" data-image="{{ asset('upload/images/' ~ sueno.fotoLink) }}" onclick="verFoto(this.getAttribute('data-image'))"><img src="{{ asset('upload/images/' ~ sueno.fotoLink) }}" class="img-responsive img-thumbnail" alt="Responsive image"></a>
                  {% elseif sueno.rol == 'video' %}
                          <div class="video-container"><iframe src="{{ sueno.linkVideo }}" frameborder="0" allowfullscreen=""></iframe></div>
                  {% endif %}
                          <h4 class="text-center titulo-sueno">{{ sueno.titulo }}</h4>
                          <h4 class="text-center quepido-sueno">{{ sueno.quePido }}</h4>
                          <p class="text-center texto-sueno info">{{ sueno.texto }}</p>   
                          <br>
                        <div>
                            {% set size = sueno.usuariosColaboradores | length %}
                            {% set size2 = sueno.usuariosSeguidores | length %}
                            <p class="text-center opciones-sueno">
                            <img src="{{ asset('bundles/estructura/images/colaboradores.png') }}" width="20" height="20" alt="Colaboradores" /> {{ size }}
                            <img src="{{ asset('bundles/estructura/images/punto.png') }}" width="5" height="5" alt="punto" />
                            <a href="{{ path('seguir', { 'suenoid': sueno.id }) }}"><img src="{{ asset('bundles/estructura/images/seguidores.png') }}" width="20" height="20" alt="Seguidores" /></a> {{ size2 }}
                            <img src="{{ asset('bundles/estructura/images/punto.png') }}" width="5" height="5" alt="punto" />
                            <img src="{{ asset('bundles/estructura/images/compartir.png') }}" width="20" height="20" alt="Compartir" />
                            </p>
                        </div>
                    <hr>
问题是,当这种呈现发生时,post将填充整个页面


我想要的只是在主页中重新呈现这篇文章

你应该使用JS前端框架,并使用Symfony2提供后端API。即使我使用Twig,内容也主要是使用Bootstrap制作的。这有帮助吗?bootstrap是一个CSS框架,而不是JS前端框架。你必须使用AJAX或者类似的东西,你需要用Symfony2提供一个API,并且为了使它更易于维护,我建议使用前端框架。顺便说一句,Twig和Bootstrap之间没有任何关系……让我告诉你,使用Bootstrap和Twig确实很有效。我真的很高兴。在另一边,我找到了twig,js(),我认为它适合我想要的东西。
                <h4 class="text-center nombre-usuario">{{ sueno.usuario.nombre ~ ' ' ~ sueno.usuario.apellido }}</h4>   
                  {% if sueno.necesitaAyuda == 1 %}
                    <p class="text-center texto-sueno"><img src="{{ asset('bundles/estructura/images/SOS.png') }}" width="25" height="25" alt="SOS" /></p>       
                  {% endif %}                    
                  {% if sueno.rol == 'foto' %}
                          <a href="#" data-toggle="modal" data-target="#imageModal" data-image="{{ asset('upload/images/' ~ sueno.fotoLink) }}" onclick="verFoto(this.getAttribute('data-image'))"><img src="{{ asset('upload/images/' ~ sueno.fotoLink) }}" class="img-responsive img-thumbnail" alt="Responsive image"></a>
                  {% elseif sueno.rol == 'video' %}
                          <div class="video-container"><iframe src="{{ sueno.linkVideo }}" frameborder="0" allowfullscreen=""></iframe></div>
                  {% endif %}
                          <h4 class="text-center titulo-sueno">{{ sueno.titulo }}</h4>
                          <h4 class="text-center quepido-sueno">{{ sueno.quePido }}</h4>
                          <p class="text-center texto-sueno info">{{ sueno.texto }}</p>   
                          <br>
                        <div>
                            {% set size = sueno.usuariosColaboradores | length %}
                            {% set size2 = sueno.usuariosSeguidores | length %}
                            <p class="text-center opciones-sueno">
                            <img src="{{ asset('bundles/estructura/images/colaboradores.png') }}" width="20" height="20" alt="Colaboradores" /> {{ size }}
                            <img src="{{ asset('bundles/estructura/images/punto.png') }}" width="5" height="5" alt="punto" />
                            <a href="{{ path('seguir', { 'suenoid': sueno.id }) }}"><img src="{{ asset('bundles/estructura/images/seguidores.png') }}" width="20" height="20" alt="Seguidores" /></a> {{ size2 }}
                            <img src="{{ asset('bundles/estructura/images/punto.png') }}" width="5" height="5" alt="punto" />
                            <img src="{{ asset('bundles/estructura/images/compartir.png') }}" width="20" height="20" alt="Compartir" />
                            </p>
                        </div>
                    <hr>
<a href="{{ path('seguir', { 'suenoid': sueno.id }) }}"><img src="{{ asset('bundles/estructura/images/seguidores.png') }}" width="20" height="20" alt="Seguidores" /></a> {{ size2 }}
    public function seguirAction($suenoid)
{

    $em = $this->getDoctrine()->getManager();

    $usuario = $this->getUser();

    $sueno = $em->getRepository('SuenoBundle:Sueno')->findOneBy(array('id' => $suenoid));

    $usuario->getSuenosSigue()->add($sueno);  
    $em->persist($usuario);
    $em->flush();

  // $suenos = $em->getRepository('SuenoBundle:Sueno')->findBy(array('usuario' => $usuario->getId()));

    //esto hay que cambiarlo entero para conseguir los sueños apropiados
        //return $this->render('EstructuraBundle:Home:home.html.twig', array('suenos'=> $suenos , 'usuario' => $usuario));
                return $this->render('SuenoBundle:Default:suenoFrontend.html.twig', array(
        'sueno' => $sueno));
}