How do i use twig for templating in my php files?

Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.

Moderator: General Moderators

Post Reply
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

How do i use twig for templating in my php files?

Post by gautamz07 »

I just want to beable to use simple twig syntex in my PHP files and so i have the following code i used composer to install twig and added the following lines of code to my index.php file:

Code: Select all

require 'vendor/autoload.php';
$loader = new Twig_Loader_Filesystem('twig_templating');
$twig = new Twig_Environment($loader);
Now when i do the following in my index.php file:

Code: Select all

{{ 'yes' }}
I get the following error:

Code: Select all

Parse error: syntax error, unexpected '}' in C:\xampp\htdocs\twig_templating\index.php on line 9
How do i use twig for templating in my php files ??
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do i use twig for templating in my php files?

Post by Celauran »

You haven't really shown much code. Are you calling render on your Twig object? That will return the HTML which you will then display, usually through a Response object.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do i use twig for templating in my php files?

Post by Celauran »

User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: How do i use twig for templating in my php files?

Post by gautamz07 »

@celauran yes i borrowed the example from there itself actually :) , i will try using the render method and see what happens.

Thank you.
Gautam.
Post Reply