Patternlab / Twig Variable Interpolation doesn't work with string from json

后端 未结 1 1140
后悔当初
后悔当初 2020-12-11 13:29

I\'m working on a project that\'s based on the twig patternlab framework. I\'m using JSON files for most of my content, especially for pages.

I want to integrate a l

相关标签:
1条回答
  • 2020-12-11 14:32

    To solve this issue you would first need to enable the extension Twig_Extension_StringLoader. This give you access to the function template_from_string, which give you the ability to "create" templates inside twig and (re)enable the string interpolation you need.

    register extension

    $twig->addExtension(new Twig_Extension_StringLoader());

    use template_from_string to achieve desired effect

    {% set legalLink = 'Datenschutzbedingungen' %}
    {{ include(template_from_string('{{ "'~contact.legal~'" }}')) }}
    
    0 讨论(0)
提交回复
热议问题