コントローラーの$this->render
第二引数に配列で渡すと、Twig側で拾えます。
###before
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class ConcertController extends Controller
{
/**
* @Route("/page/")
**/
public function indexAction()
{
return $this->render('Page/index.html.twig');
}
}
###after
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class ConcertController extends Controller
{
/**
* @Route("/page/")
**/
public function indexAction()
{
$information = "add new concert";
$args = [
'informations' => [
'201610' => 'Add new page',
'201611' => 'Add news page',
'201612' => 'Delete old page',
],
'title' => 'Example Site'
];
return $this->render(
'Page/index.html.twig',
$args
);
}
}
##Twigで拾う
渡した値は、第二引数のキー名で拾えます。
<html>
<body>
<h1>{{ title }}</h1>
<ul>
{% for key, item in informations %}
<li>{{ key }}: {{ item }}</li>
{% endfor %}
</ul>
</body>
</html>