I am trying to get a block from a twig template them render 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 get it 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 having 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 dont know what to use to get the container running.
There is no getContainer()
method for a controller.
You could access it by $this->container
directly like $this->container->get('twig')
But Symfony provide shortcut method for controller, you could use $this->get('twig')
too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With