有几种方法可以实现:
1)在index.html和content.html等文件中分离你的index.html.
然后在index.html中使用include函数来包含content.html.
示例:
if(isAjaxRequest()) //try to find the right function here
echo $twig->render('content.html','go' => 'here'))
else
echo $twig->render('index.html','go' => 'here'));
编辑:
如果你用jQuery做你的ajax请求,例如:
$.get('yoururl',function(data) {
$('#divtoremplace').html(data);
});
2)在index.html中使用request.ajax boolean
{% if request.ajax == false %}
My header,not reloaded with ajax
{% endif %}
My content,reloaded with ajax
{% if request.ajax == false %}
Other content,not reloaded with ajax
{% endif %}
不知道第二个,但是这应该是文档的诀窍.最好的方法是第一个解决方案,分离你的代码.