Page 1 of 1

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

Posted: Thu Dec 29, 2016 3:01 pm
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 ??

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

Posted: Sat Dec 31, 2016 9:58 am
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.

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

Posted: Sat Dec 31, 2016 10:04 am
by Celauran

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

Posted: Sun Jan 01, 2017 9:09 am
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.