我正在尝试从twig模板中获取一个块,并将其呈现到我的索引模板中:
我不知道该使用什么来运行容器。
{% 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 %}
然后使用以下方式将其传递到我的控制器
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');
然后在我的索引模板中使用它。
{{dynamic}}
但是我遇到了一个问题,Symfony 提示
FatalErrorException: Error: Call to undefined method
Alvin\MainBundle\Controller\IndexController::getContainer() in /Users/alvinvaldez/Sites/alvinwebsite/src/Alvin/MainBundle/Controller/IndexController.php line 26
我不知道该使用什么来运行容器。