I have this conditional included in a layout file I use within others, using the extends feature in twig.
This is at the very top of _layouts/application.twig
{% if not currentUser %}
{% redirect "login" %}
{% endif %}
I have this at the very top of account/index.twig
{% extends "_layouts/application" %}
{% set name = currentUser.getFullName() %}
If the user is not logged in, I expect it to redirect the user to the login page, as it contains the if not currentUser conditional at the very beginning of the extends file: _layouts/application.twig
I then copied and pasted the if not currentUser code and placed it above the extends call within the account/index.twig file (like seen below):
{% if not currentUser %}
{% redirect "login" %}
{% endif %}
{% extends "_layouts/application" %}
and it works as I expect it to.
Why does it not work with the if conditional being included in _layouts/application.twig file that I include by using {% extends "_layouts/application" %}