Craft CMS Asked by Terry Upton on September 8, 2020
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 <meta> tags that should be included in the <head> #}
{% block headMeta %}
{% endblock headMeta %}
{# -- Any <link> tags that should be included in the <head> #}
{% block headLinks %}
{% endblock headLinks %}
{# -- Any CSS that should be included before </head> -- #}
{% block headCss %}
{# Google fonts #}
<link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@300;400;500;600;700&display=swap" rel="stylesheet">
{% 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#}
<div class="max-w-2xl fixed bottom-0 left-0 border border-green-400 m-2">
<div class="flex">
<div class="bg-green-100 p-3 text-green-500 text-sm flex">
{{ 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.
</div>
<button class="bg-green-500 text-white p-2">
{{ svg('@icons/bx/bx-info-circle.svg', class="w-8 h-8 flex-shrink-0 fill-current") }}
</button>
</div>
</div>
{% endif %}
<div id="page-container">
{# -- Info header, including _navbar.twig -- #}
{% include "_globals/header.twig" %}
{# - IE notice for Old browsers - #}
{% include '_globals/ie-notice.twig' %}
<main>
{# -- Primary content block -- #}
{% block content %}
{% endblock %}
</main>
{# -- Content that appears below the primary content block -- #}
{% block subcontent %}
{% endblock %}
{# -- Info footer -- #}
{% include "_globals/footer.twig" %}
</div>
{% endblock bodyHtml %}
Try inside this in the main template file:
{% block access %}
{% requireLogin %}
{% endblock %}
Answered by Pavel Pavlovich on September 8, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP