多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# `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