Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 448
sampereless Avatar asked Aug 16 '26 18:08

sampereless


1 Answers

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

 <div id="1"> {{ greet|raw }} Jeremy</div>
 <div id="1"> {{ greet|raw }} Davis</div>
like image 164
Imanali Mamadiev Avatar answered Aug 19 '26 11:08

Imanali Mamadiev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!