PHP Developers Network
http://forums.devnetwork.net/

How do i use twig for templating in my php files?
http://forums.devnetwork.net/viewtopic.php?f=72&t=143238
Page 1 of 1

Author:  gautamz07 [ Thu Dec 29, 2016 4:01 pm ]
Post subject:  How do i use twig for templating in my php files?

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:

Syntax: [ Download ] [ Hide ]
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:

Syntax: [ Download ] [ Hide ]
{{ 'yes' }}
 


I get the following error:

Syntax: [ Download ] [ Hide ]
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 ??

Author:  Celauran [ Sat Dec 31, 2016 10:58 am ]
Post subject:  Re: How do i use twig for templating in my php files?

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.

Author:  Celauran [ Sat Dec 31, 2016 11:04 am ]
Post subject:  Re: How do i use twig for templating in my php files?

Have you read this? http://twig.sensiolabs.org/doc/api.html

Author:  gautamz07 [ Sun Jan 01, 2017 10:09 am ]
Post subject:  Re: How do i use twig for templating in my php files?

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

Thank you.
Gautam.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/