合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# `template_from_string` New in version 1.11: The `template_from_string` function was added in Twig 1.11. The `template_from_string` function loads a template from a string: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2</pre></div></td><td class="code"><div class="highlight"><pre>{{ include(template_from_string("Hello {{ name }}")) }} {{ include(template_from_string(page.template)) }} </pre></div></td></tr></table> Note The `template_from_string` function is not available by default. Youmust add the `Twig_Extension_StringLoader` extension explicitly whencreating your Twig environment: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 2</pre></div></td><td class="code"><div class="highlight"><pre>$twig = new Twig_Environment(...); $twig-&gt;addExtension(new Twig_Extension_StringLoader()); </pre></div></td></tr></table> Note Even if you will probably always use the `template_from_string` functionwith the `include` function, you can use it with any tag or function thattakes a template as an argument (like the `embed` or `extends` tags). ### Arguments - `template`: The template