drcx71276 2016-04-11 18:33
浏览 79
已采纳

PHP把html放在一个twig变量里面?

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>
  • 写回答

1条回答 默认 最新

  • dsndm82062 2016-04-12 06:24
    关注
     {% set greet = "<strong>hello</strong>" %}
    
     <div id="1"> {{ greet|raw }} Jeremy</div>
     <div id="1"> {{ greet|raw }} Davis</div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站