run model function from inside twig

New topics about Symfony 2 should go here

Moderators: dcobalt, tiagojsag

run model function from inside twig

Postby roy782 » Thu Apr 12, 2012 5:50 pm

Hi all,
wanted to know if it's possible to run a class method from inside twig
lets say i have a class name model
and there is model.generateHtml() which just returns a string of html rep

in controller:
Code: Select all
return $this->render('Bundle:Result:result.html.twig', array('model' => $model));


in result.html.twig:
Code: Select all
{{model.generateHtml()}}

tried both with parenthesis and without but nothing is working
any suggestions?
thanks
Roy
roy782
Junior Member
 
Posts: 11
Joined: Tue Apr 10, 2012 2:34 pm

Re: run model function from inside twig

Postby althaus » Thu Apr 12, 2012 6:09 pm

Normally you should be able to call any entity method from Twig:

http://twig.sensiolabs.org/doc/templates.html#variables

What's happening?
althaus
Faithful Member
 
Posts: 605
Joined: Tue Oct 18, 2011 2:20 pm
Location: Germany

Re: run model function from inside twig

Postby roy782 » Tue Apr 17, 2012 8:22 am

yeah...
it worked...
wierd it didn't worked for me before
roy782
Junior Member
 
Posts: 11
Joined: Tue Apr 10, 2012 2:34 pm


Return to General Symfony 2 discussion

Who is online

Users browsing this forum: No registered users and 4 guests