I define variable in controller and pass it to template but it’s not visible in extend block. The important controller code is:
$response['html'] = $this->renderView(
'AldenXyzBundle:Profile:edit_ajax.html.twig', array(
'isXmlHttpRequest' => $request->isXmlHttpRequest(),
)
);
and Twig template
{% extends isXmlHttpRequest ? '::base-ajax.html.twig' : '::base.html.twig' %}
{% block content %}
...
{% endblock %}
and I have exception Variable "isXmlHttpRequest" does not exist in ... while the template
{% extends '::base-ajax.html.twig' %}
{% block content %}
{{ dump(isXmlHttpRequest) }}
...
{% endblock %}
works well and display correct $isXmlHttpRequest value.
I also tried directly in template:
{% extends app.request.isXmlHttpRequest ? '::base-ajax.html.twig' : '::base.html.twig' %}
but I got an exception saying app is undefined.
I’m using symfony v2.0.15 and twig v1.8.2
This will work: