2016-02-14 104 views
1

我有我的基本模板注入額外塊到樹枝模板

<html> 
<head> 
..... 
</head> 

<body> 
{% block body_content %}{% endblock %} 

{% block debug_output %}{% endblock %} 
</body> 

</html> 

和我的頁面模板

{% extends "base.html.twig" %} 
{% block body_content %} 
..... 
{% endblock %} 

現在,經過我已經裝我要添加的東西到debug_output塊模板。

{% block debug_output %} 
..... 
{% endblock %} 

有誰知道我該怎麼做?

不使用任何框架只是樹枝作爲我的模板引擎。


這是調用模板的流程我現在有

$loader = new Twig_Loader_Filesystem(); 
$twig = new Twig_Environment($loader); 
$template = twig->loadTemplate($page_template); 
/* Add additional template to insert into debug_output block here */ 
$template->render($vars); 
+0

'加載'後,你的意思是你需要添加Ajax內容? – pbenard

+0

這是調用模板的流程我目前有 '$ loader = new Twig_Loader_Filesystem(); $ twig = new Twig_Environment($ loader); $ template = twig-> loadTemplate($ template); */ $ template-> render($ vars);' – Chris

+0

也許你可以用這個[plugin]做一些事情(https://github.com/rybakit/twig-擴展遞延型)。它延遲了你用'defered'標記的某個'block'的渲染 – DarkBee

回答

0

在我放棄了年底,我想出了是不是使用塊的解決方案,但一個對象變量並在屬性上循環添加我想要的調試信息。該對象與$ vars合併並傳遞到$template->render($vars)行。