javascriptphphtmlsymfonytwig

PHP put html inside a twig variable?


Hello I am trying to try something that is expieremental and not really sure if it's possible. I have a twig template with some html that is duplicated on the page and I am wondering if it's possible to create a variable in twig that holds a snippet of html (must include html markup) that i can then call throughout the page instead of repeating myself.... thanks in advance

    <!DOCTYPE html>
   <html>
    <head>
       <title>My Webpage</title>
     </head>
     <body>

     {% set greet = "<strong>hello</strong>" %}

     <div id="1"> {{ greet }} Jeremy</div>
     <div id="1"> {{ greet }} Davis</div>

   </body>
 </html>

Solution

  •  {% set greet = "<strong>hello</strong>" %}
    
     <div id="1"> {{ greet|raw }} Jeremy</div>
     <div id="1"> {{ greet|raw }} Davis</div>