I’m using Twig with Silex and are having some trouble with extend within an if statement. Basically the page is being extended even tho, the request is not done by AJAX.
{% if app.request.isXmlHttpRequest == false %}
{% extends 'layout.html.twig' %}
{% endif %}
However this works. The button is only being showed when the request is AJAX based.
{% if app.request.isXmlHttpRequest %}
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
{% endif %}
Also possibly worth mentioning my code is enclosed in an {% block content %} tag.
Does anyone have experience with this issue? (Being able to extend only if isXmlHttpRequest is false)
Thanks in advance
Try this one:
Behind the courtains
extendsis a token parsed in a way that no conditions can be placed around it, the outcome will be what you got: your template is always extended.I’m not sure how it’ll work with the empty string, you may need to create a “layout-ajax.html.twig” file with no content but the block you want to override.