2
votes

I started develop in symfony now and i work in a CMS with Symfony CMF, i need to create a function with some lines in php and JS to insert into in running page or a existing template.

I created a Action at main controller for this template and i try render controller inside a twig with this line:

{{ render(controller('siteCmsBundle:Article:fish')) }}

But this return a blank page, i tried also this code:

{% render 'siteCmsBundle:Article:fish' %}

This return a route error (logical).

And the controller is:

<?php

namespace site\Bundle\CmsBundle\Controller;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Wf\Bundle\CmsBaseBundle\Controller\ArticleController as BaseArticleController;
use  Wf\Bundle\CmsBaseBundle\Entity\Collection\Module\PageCompositeEditorModule;

class ArticleController extends BaseArticleController
{

   ...

    /**
     * @Template()
     */
    public function fishAction(){

        return new Render("Test");
    }
}

Well, i'll continue to learn this framework, but i need conclude this issue today. :(

Can someone help me with this?

Thanks a lot!

1
If your action is called myAction, you should do this : {{ render(controller('CmsBundle:Article:my')) }} (remove the Action suffix). Anyway, a blank page often means a server side error (500 error). So you should have errors in your logs (either symfony or apache) - Brewal
Hello, sorry i edited the post now. myAction was an exemple. - diegoos
return new Render("Test"); ? Try: return new Response("Test"); - scoolnico
Man! It's working!! But, i need add this line use Symfony\Component\HttpFoundation\Response; - diegoos
Thanks a lot! Brewal and scoolnico :) - diegoos

1 Answers

2
votes

Use annotation and just return single array.

/**
 * @Template()
 */
public function fishAction(){

    return 
        array('fish' => 'saumon');
}

OR Add to method render() who extend of Controller class the template.

public function fishAction(){
    return $this->render(
        'siteBundle:CmsBundle:fishTemplate.html.twig',
        array('fish' => 'saumon')
    );
}