<p>Try inside this in the main template file:</p>
<pre><code>{% block access %}  
    {% requireLogin %}
{% endblock %}
</code></pre>

CC BY-SA 4.0
2020-07-29T11:11:49.073Z
I am afraid this didn't work either @pavelpavlovich
Terry Upton
CC BY-SA 4.0
2020-07-18T20:15:17.707Z
2020-07-18T20:15:17.707Z
Pavel Pavlovich
<p>Is there a reason <code>{% requireLogin %}</code> is not firing when using in a parent include?</p>
<p>if I place <code>{% requireLogin %}</code> inside the main template file and then use this like so:</p>
<p>homework.twig<br />
<code>{% extends &quot;_layouts/members-page-layout.twig&quot; %}</code></p>
<p>It is not firing? But if I put it inside the homework.twig file directly it fires....
Was hoping t avoid having to add it to multiple templates and just add it to a 'members' parent layout template.</p>
<p><strong>EDIT 18 July 2020</strong><br />
Editing the post to include more information
Here is the parent template I am trying to include the <code>{% requireLogin %}</code> that is not firing.</p>
<pre><code>{# -- Layout template for HTML pages -- #}
{% extends &quot;_boilerplate/_layouts/base-html-layout.twig&quot; %}

{# -- Any &lt;meta&gt; tags that should be included in the &lt;head&gt; #}
{% block headMeta %}
{% endblock headMeta %}

{# -- Any &lt;link&gt; tags that should be included in the &lt;head&gt; #}
{% block headLinks %}
{% endblock headLinks %}

{# -- Any CSS that should be included before &lt;/head&gt; -- #}
{% block headCss %}
  {# Google fonts #}
  &lt;link href=&quot;https://fonts.googleapis.com/css2?family=Quicksand:wght@300;400;500;600;700&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;
  
  {% include &quot;_inline-css/site-fonts.css&quot; %}
{% endblock headCss %}

{% requireLogin %}

{# -- Page body -- #}
{% block bodyHtml %}
  {% set primarySectionColor      = 'navy' %}
  {% set secondarySectionColor    = 'pink' %}
  
  {% if currentUser.admin %}
    {#    TODO: Make this hide#}
    &lt;div class=&quot;max-w-2xl fixed bottom-0 left-0 border border-green-400 m-2&quot;&gt;
      &lt;div class=&quot;flex&quot;&gt;
        &lt;div class=&quot;bg-green-100 p-3 text-green-500 text-sm flex&quot;&gt;
          {{ svg('@icons/bx/bx-info-circle.svg', class=&quot;w-5 h-5 flex-shrink-0 fill-current mr-1&quot;) }}
          You are currently logged in as an admin role so you have unrestricted access and therefore you will not see the filtering of content and homework like a member user
          (parent) would see.
        &lt;/div&gt;
        &lt;button class=&quot;bg-green-500 text-white p-2&quot;&gt;
          {{ svg('@icons/bx/bx-info-circle.svg', class=&quot;w-8 h-8 flex-shrink-0 fill-current&quot;) }}
        &lt;/button&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  {% endif %}
  
  &lt;div id=&quot;page-container&quot;&gt;
    {# -- Info header, including _navbar.twig -- #}
    {% include &quot;_globals/header.twig&quot; %}
    
    {# - IE notice for Old browsers - #}
    {% include '_globals/ie-notice.twig' %}
    
    &lt;main&gt;
      {# -- Primary content block -- #}
      {% block content %}
      {% endblock %}
    &lt;/main&gt;
    
    {# -- Content that appears below the primary content block -- #}
    {% block subcontent %}
    {% endblock %}
    
    {# -- Info footer -- #}
    {% include &quot;_globals/footer.twig&quot; %}
  
  &lt;/div&gt;
{% endblock bodyHtml %}
</code></pre>

CC BY-SA 4.0
2020-07-14T08:51:18.443Z
Sorry this is not going to be very helpful for you, but I can say: It Works OK For Me. Do you maybe have some kind of caching going on?
James Smith
CC BY-SA 4.0
2020-07-14T12:19:06.843Z
No caching as local development at this stage. 
I will have another look then, at least you've confirmed it _should_ work ok.
Thanks.
Terry Upton
CC BY-SA 4.0
2020-07-15T15:39:53.067Z
What's in your main template file?
RitterKnight
CC BY-SA 4.0
2020-07-18T16:17:41.443Z
I have added more information to the original question. @RitterKnight
Terry Upton
CC BY-SA 4.0
2020-07-18T20:28:23.627Z
@TerryUpton: if you move the ``{% requireLogin %}`` tag before ``{% extends %}`` does it work?
RitterKnight
CC BY-SA 4.0
2020-07-29T11:12:24.463Z
@RitterKnight nope it's the same even if before the `{% extends %}`
Terry Upton
CC BY-SA 4.0
2020-07-29T15:00:03.153Z
What's inside ``base-html-layout.twig``? Sounds like you may have too many extends going on? You could end up in a situation where you think a tag is going to fire but it's never going to because something else is actually extending it.  That sounds like what could be happening. I would also make sure you're actually not logged in while testing.
RitterKnight
CC BY-SA 4.0
2024-04-05T10:35:27.047Z
Funny how these things come around again... 4 years after my first comment on this question saying it works ok for me, I'm now running into this problem myself! Did you ever get it resolved?!
James Smith
<templating><requirelogin>
{% requireLogin %} not working on extended (layout template) files?
# {% requireLogin %} not working on extended (layout template) files?

(Asked by: username_0 on 2020-07-14)

Is there a reason {% requireLogin %} is not firing when using in a parent include?
if I place {% requireLogin %} inside the main template file and then use this like so:
homework.twig
{% extends "_layouts/members-page-layout.twig" %}
It is not firing? But if I put it inside the homework.twig file directly it fires....
Was hoping t avoid having to add it to multiple templates and just add it to a 'members' parent layout template.
EDIT 18 July 2020
Editing the post to include more information
Here is the parent template I am trying to include the {% requireLogin %} that is not firing.
{# -- Layout template for HTML pages -- #}
{% extends "_boilerplate/_layouts/base-html-layout.twig" %}

{# -- Any  tags that should be included in the  #}
{% block headMeta %}
{% endblock headMeta %}

{# -- Any  tags that should be included in the  #}
{% block headLinks %}
{% endblock headLinks %}

{# -- Any CSS that should be included before  -- #}
{% block headCss %}
  {# Google fonts #}
  
  
  {% include "_inline-css/site-fonts.css" %}
{% endblock headCss %}

{% requireLogin %}

{# -- Page body -- #}
{% block bodyHtml %}
  {% set primarySectionColor      = 'navy' %}
  {% set secondarySectionColor    = 'pink' %}
  
  {% if currentUser.admin %}
    {#    TODO: Make this hide#}
    
      
        
          {{ svg('@icons/bx/bx-info-circle.svg', class="w-5 h-5 flex-shrink-0 fill-current mr-1") }}
          You are currently logged in as an admin role so you have unrestricted access and therefore you will not see the filtering of content and homework like a member user
          (parent) would see.
        
        
          {{ svg('@icons/bx/bx-info-circle.svg', class="w-8 h-8 flex-shrink-0 fill-current") }}
        
      
    
  {% endif %}
  
  
    {# -- Info header, including _navbar.twig -- #}
    {% include "_globals/header.twig" %}
    
    {# - IE notice for Old browsers - #}
    {% include '_globals/ie-notice.twig' %}
    
    
      {# -- Primary content block -- #}
      {% block content %}
      {% endblock %}
    
    
    {# -- Content that appears below the primary content block -- #}
    {% block subcontent %}
    {% endblock %}
    
    {# -- Info footer -- #}
    {% include "_globals/footer.twig" %}
  
  
{% endblock bodyHtml %}

**Tags:** templating, requirelogin
> **Comments:**
> **username_1**: Sorry this is not going to be very helpful for you, but I can say: It Works OK For Me. Do you maybe have some kind of caching going on?  
> **username_0**: No caching as local development at this stage.  I will have another look then, at least you've confirmed it _should_ work ok. Thanks.  
> **username_2**: What's in your main template file?  
> **username_0**: I have added more information to the original question. @RitterKnight  
> **username_2**: @TerryUpton: if you move the ``{% requireLogin %}`` tag before ``{% extends %}`` does it work?  
> **username_0**: @RitterKnight nope it's the same even if before the `{% extends %}`  
> **username_2**: What's inside ``base-html-layout.twig``? Sounds like you may have too many extends going on? You could end up in a situation where you think a tag is going to fire but it's never going to because something else is actually extending it.  That sounds like what could be happening. I would also make sure you're actually not logged in while testing.  
> **username_1**: Funny how these things come around again... 4 years after my first comment on this question saying it works ok for me, I'm now running into this problem myself! Did you ever get it resolved?!  

---

## 1 answers

### Answer by username_3 on 2020-07-18. Score: 1

Try inside this in the main template file:
{% block access %}  
    {% requireLogin %}
{% endblock %}

> **Comments:**
> **username_0**: I am afraid this didn't work either @pavelpavlovich  

---

