Twig Property

Allows access to the current request object, including request method.

# this.request.method

You can access the current request method object via this.request.method and it returns the HTTP verb in uppercase.

{% if this.request.method == 'GET' %}
    <!-- Do GET Logic -->
{% else this.request.method == 'POST' %}
    <!-- Do POST Logic -->
{% endif %}

# this.request.ajax

To check if the current request uses the AJAX header, access the this.request.ajax property.

{% if this.request.ajax %}
    Request was submitted via AJAX
{% endif %}

# this.request.pjax

To check if the current request was made using the Turbo Router, access the this.request.pjax property.

{% if this.request.pjax %}
    Request was submitted via PJAX
{% endif %}