Ответ 1
Существует несколько способов сделать это:
1) Отделите свой index.html в нескольких файлах, таких как index.html и content.html. Затем используйте include функцию в index.html, чтобы включить content.html.
Пример:
if(isAjaxRequest()) //try to find the right function here
echo $twig->render('content.html', array('the' => 'variables', 'go' => 'here'))
else
echo $twig->render('index.html', array('the' => 'variables', 'go' => 'here'));
Изменить: Если вы выполняете свой запрос ajax с помощью jQuery, например:
$.get('yoururl', function(data) {
$('#divtoremplace').html(data);
});
2) Используйте request.ajax
boolean в вашем index.html
{% if request.ajax == false %}
<p>My header, not reloaded with ajax</p>
{% endif %}
<p>My content, reloaded with ajax</p>
{% if request.ajax == false %}
<p>Other content, not reloaded with ajax</p>
{% endif %}
Не уверен во втором, но это должно делать трюк в соответствии с документацией. Лучший способ - это первое решение, отделите свой код.