header
The header function allows you to set an HTTP header for the response.
This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{% do header('Pragma', 'cache') %}
An example could be to set caching information.
{# Tell the browser to cache something for 30 days #}
{% set expiry = now|date_modify('+30 days') %}
{% do header('Cache-Control','max-age=' ~ (expiry.timestamp - now.timestamp)) %}
{% do header('Pragma', 'cache') %}
{% do header('Expires', expiry|date('D, d M Y H:i:s', 'GMT') ~ ' GMT') %}
You can pass the header and the value as two parameters like the above example. Or, you can pass the entire header value to the first parameter only.
{% do header('Content-Type: application/json; charset=utf-8') %}
Arguments
The header function has the following signature.
header(http_header_name, http_header_value)
{# or pass the entire header to the first parameter #}
header(http_header_name_and_value)
| Argument | Description |
|---|---|
| http_header_name |
Required The name of the header to set.
|
| http_header_value |
The value of the header to set.
If you do not pass this value then you need to pass the entire header name and value to the first parameter. |