GetContainer in symfony

Hey guys, I'm trying to get a block from a branch template, they map it to my index template:

{% block round1 %}
<h1> hello this is a sample for a round 1</h1>
{% endblock %}

{% block round2 %}
<h1> hello this is a sample for a round 1</h1>
{% endblock %}

then go to my controller using

  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Alvin\MainBundle\Entity\User;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  use Alvin\MainBundle\Form\Type\ResetPasswordType;


  $templateContent = $this->getContainer()->get('twig')->loadTemplate('AngpaoMainBundle:Dynamic:dynamic.html.twig');
  $bodydynamics = $templateContent->renderBlock('round1');

then use it in my index template

{{dynamic}}

but then im has a problem and symfony says

FatalErrorException: Error: Call to undefined method 
Alvin\MainBundle\Controller\IndexController::getContainer() in /Users/alvinvaldez/Sites/alvinwebsite/src/Alvin/MainBundle/Controller/IndexController.php line 26

I do not know what to use to start the container. help the guys.

btw: newbie level in symfony

tnx in advanced mode

+4
source share
1 answer

There is no method for the controller getContainer().

You can access it $this->containerjust like$this->container->get('twig')

But Symfony provides a shortcut for the controller, you can use $this->get('twig')too.

+7
source

All Articles