嫩枝,得到源
问题描述:
我怎样才能得到模板与extend
:嫩枝,得到源
//first.html.twig
<div>
{% block test %}
{% endblock %}
</div>
而且second.html.twig
:
{% extend "first.html.twig" %}
{% block test %}
{% if test = 'foo' %}
{{ test }}
{% endif %}
{% endblock %}
在php文件:
<?php
$load = ???('second.html.twig');
$source = $load->getSource();
//$source:
//<div>
// {% if test = 'foo' %}
// {{ test }}
// {% endif %}
//</div>
答
如在documentation中看到的那样,您可以将布局设置为模板。例如:
从技术文档
// {% extends layout %}
// deprecated as of Twig 1.28
$layout = $twig->loadTemplate('some_layout_template.twig');
// as of Twig 1.28
$layout = $twig->load('some_layout_template.twig');
$twig->display('template.twig', array('layout' => $layout));
我想你应该解释的背景下,发展你的问题。你真的在找什么? – AnthonyB
@AnthonyB我想发送树枝在其他服务器解析,并希望用json发送一些源代码,并得到回报的HTML。 – Iwan
我现在明白了,谢谢。路径是否正确?在Twig引擎中,可以设置一个模板目录,在这个文件夹中是first.html.twig? – AnthonyB