Conflict on Template of Twig and Vue.js

后端 未结 10 2271
一向
一向 2020-12-02 16:27

I\'m doing a program using Slim 2 that uses Twig as my templating engine. so It uses the syntax {{ foo }} in php file. On the other hand, I\'m using vue.js, it

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 17:23

    The best solution is not to change either ones delimiter.

    You can use the vuejs markup in twig like so

    {{ mytwigvar }} {{ '{{' }} myvuevar {{ '}}' }}
    

    This obviously is suboptimal, so redefine your twig loader to preprocess files and replace {{{ with {{ '{{' }} and }}} with {{ '}}' }} then you can write the markup as

    {{ mytwigvar }} {{{ myvuevar }}}
    

    Much nicer.

提交回复
热议问题