Sky21.86 Sky21.86 - 9 days ago 5
Twig Question

How to paste link into html template in Symfony

i am using symfony 3 to input a link into my HTML template, which is saved as a database entry in the table. I can get the html version of the template (by quering for html_body from the databse) and string version of the link.

Question is: what is the best way to input my link into specific section of my html template.

More general question: how do i insert one html element into specific section of another html element given above input.

I was thinking about using twig variable like

{{ link }}
and then rendering my temaplte and passing link into it as a variable. But i do not have this temaplte file saved anywhere so cannot reffer to it as

renderView('FrontEnd/emailSubscribe.html.twig', ['link' => $urlButton]));

Value of
file is saved in the the variable
, which I query from my DB.

Any assistance with my issue is highly appreciated.


You can render a Twig template from string.

Assuming you have your template in $templateBody and the link in $urlButton you can do that like this:

$template = $this->get('twig')->createTemplate($templateBody);
$renderedString = $template->render(array('link' => $urlButton));