2

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!

8
  • 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) Commented Oct 16, 2015 at 14:44
  • Hello, sorry i edited the post now. myAction was an exemple. Commented Oct 16, 2015 at 14:52
  • 1
    return new Render("Test"); ? Try: return new Response("Test"); Commented Oct 16, 2015 at 14:54
  • Man! It's working!! But, i need add this line use Symfony\Component\HttpFoundation\Response; Commented Oct 16, 2015 at 15:03
  • Thanks a lot! Brewal and scoolnico :) Commented Oct 16, 2015 at 15:04

1 Answer 1

2

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')
    );
}
Sign up to request clarification or add additional context in comments.

3 Comments

Hi. I tried to use this options, but return "Page not found".
Add customize template 'siteBundleCmsBundle:Fish:fishTemplate.html.twig', into site\Bundle\CmsBBundle\Resources\views\Fish\fishTemplate.html.twig
rommct, it's works! Thanks. But, the script tag doesn't work when i render controller with only <script>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.