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?
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.