0
votes

I need replace some content in every file of view. But content in many places is just a text, not a variable, co i cant use variable|replace() filter.

Is there any way to get view (eg in Controller) content before displaying so I can pass it to some function and return ready to display content? Or maybe there is way for replace all content in block tag?

1
$this->renderView(twigname,array('text_to_replace''=>$text). Is this what you are looking for?jonju
Why dont you just change your views and make it a variable?NDM

1 Answers

1
votes

Symfony controller has 2 functions render() and renderView(), the former renders a view and returns a Response, the latter just renders the view and returns the string result.

so you could in your action:

$content = $this->renderView('my-view.html.twig', [...]);

$content = str_replace('my text', 'my new text', $content);

return new Response($content);