Philemon philip Kunjumon
Philemon philip Kunjumon

Reputation: 1422

Extended use of replace filter in twig?

i checked out the documentation for the replace filter in twig. my problem is that, suppose i have a variable say contvariable, and the content passed through that variable from the controller is dynamic

 return $this->render('RodasysFormstudyBundle:Default:addclientname.html.twig', array('contvariable' =>$sometext));

this $sometext variable will contain texts like

$sometext='%Sun% rises in the East';

the text inside the %% should be displayed as an input field in the browser. I did not find any examples in the web like to replace the content inside the %% (what ever the content be whether its sun or the moon). Is this possible to do this using replace filter or should i follow some other method such as to replace the content in controller before sending it to twig..

please help..

Upvotes: 2

Views: 3375

Answers (1)

maxdec
maxdec

Reputation: 5725

You could do something like that (with the 'raw' filter) :

{{ "%foo% rises in the East"|replace({'%foo%': "<input type='text' name='"~foo~"' value='"~foo~"'/>"})|raw }}

foo is a variable sent by your controller, with the value of your choice.

Upvotes: 2

Related Questions