Create and use new templates in Symfony2

Hi guys, today I want to speak again about the Symfony2 Framework. In this tutorial I will show you how you can create and use templates in Symfony2.6 Framework.

To create a new template, you must only go to your views folder and create a new file(example: new.html.twig). Then you can add this simple code in your new template:

<!DOCTYPE html>
<html>
<head>
<title>Welcome to Symfony!</title>
</head>
<body>
<h1>{{ page_title }}</h1>

</body>
</html>

Next open your controller and add this code at your action:

return $this->render('NewNewBundle:Default:new.html.twig',array('page_title'=>'New Template'));

Now your template will show this text: New Template

As you can see its very simple to create and use the templates in Symfony2 Framework.

Video tutorial:









Leave a Comment