Twig does not works

Created on 2 Apr 2017  ·  9Comments  ·  Source: twigphp/Twig

Hello

I have downloaded vendor using "composer require twig/twig" using that I find vendor folder.Now I have have start working on twig development .

I create index.php file which has this code

"

require 'vendor/autoload.php'

$loader = new Twig_Loader_Filesystem('views');

$twig = new Twig_Environment($loader);

$twig->render('hello.html' , array(

'name' => 'Micheal',
'age' => 52

));
?>"
And also create hello.html file

Hello,,{{name}}

I run this using xampp server but facing this error.

Parse error: syntax error, unexpected '$loader' (T_VARIABLE) in C:\xampp\htdocs\Twig\index.php on line 5

Kindly help me out I need to submit this today.So, please help me to get rid of it

Most helpful comment

require 'vendor/autoload.php' => require 'vendor/autoload.php'_;_
dont forget ";"

All 9 comments

require 'vendor/autoload.php' => require 'vendor/autoload.php'_;_
dont forget ";"

Thanks for your response , I have added this correction.
But still I am not getting desire output. I am showing blank page

The render method will return, so you need to add echo for it.
http://twig.sensiolabs.org/doc/2.x/intro.html#basic-api-usage

Yeah, either echo the return value of render(), or use display() instead.

Thanks for your support it is working well now.
Can I developed the twig template for generating pdf invoice.
If yes then How it would work because I have developed the project but it is showing pdf without the value of twig

Twig is used as a templating engine (providing escaping, variables, basic logic, etc) for any text-based file, including an uncompressed PDF. That said, I would not necessarily recommend it for creating PDF documents, nor is doing so really within the scope of this issue tracker. Otherwise, if you are asking something else, I don't quite follow.

Closing as the original problem has been solved. @manishakumaribajaj You should use StackOverflow for support.

You can use Twig to render a template and then capture this output with https://github.com/KnpLabs/snappy (webkit-based headless browser). Use page-break: force (in CSS) to force a new page if you need tranporter pages.

But please ask further questions on StackOverflow 👍

Thanks sir

On Thu, Apr 6, 2017 at 12:11 PM, Sebastiaan Stok notifications@github.com
wrote:

You can use Twig to render a template and then capture this output with
https://github.com/KnpLabs/snappy (webkit-based headless browser). Use page-break:
force (in CSS) to force a new page if you need tranporter pages.

But please ask further questions on StackOverflow 👍


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/twigphp/Twig/issues/2437#issuecomment-292088564, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AZm3LMS4s1NVqDMHjK50eXUl0HKQpoIvks5rtJAIgaJpZM4MwwXR
.

Was this page helpful?
0 / 5 - 0 ratings