Reputation: 391
In php I can use in my template:
use My\WebBundle\Classes\Util;
How can I put the same in Twig tempate?
Thanks.
Upvotes: 0
Views: 240
Reputation: 12306
You can't create objects in twig template, but you can pass them in twig template from controller:
public function postsAction() {
return $this->render('AcmeBlogBundle:User:posts.html.twig', array(
'util' => new My\WebBundle\Classes\Util(),
));
}
And in twig template can use it:
{{ util.anyProperty }}
Upvotes: 3
Reputation: 2835
You don't want PHP in your twig template. All you need to do is tell twig what variables you use. It's part of the MVC.
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
Upvotes: 1