if I have a homepage that displays 5 slides
can I set each slide to be visible if you are a member of a group?
-slide 1 - group 1
-slide 2 - group 2
-slide 3 - group 1 and 2
etc
currently i display my slides with this code on the home page
{% for child in collection %}
{% include 'slide.html.twig' with {'blog': page, 'page': child, 'truncate': true} %}
{% endfor %}
and have 5 subpages slide.md containing
access:
site.paid: true
this doesn’t work, but not sure if it is possible and how to go about it, any hints would be great
@dean_007, Grav’s permissions does not provide the granularity on a image by image basis. A user either has or has no permission to see the page.
Having said that… Inside your loop, I suspect you can check the group of the user using grav.user.groups
and only include the slide when the user belongs to the correct group.
See Theme Variables | Grav Documentation
Ok i can see where you are going with this
So if i were to create a variable like this
allowedGroups:
- group1
- group2
var display = false;
{% for child in collection %}
{% if config.plugins.login.enabled and grav.user.username %}
{% for g in allowedGroups %}
{% if g == grav.user.group %}
display =true
{% else %}
display = false
{% endif %}
{% endfor %}
{% endif %}
{% if display == true or allowedGroups is empty %}
{% include 'slide.html.twig' with {'blog': page, 'page': child, 'truncate': true} %}
{% endif %}
display = false
{% endfor %}
This was typed on my phone so might not be absolutely correct, but ill give it a go.
Thanks for the idea, ill report back with how i go.
@dean_007, Small correction, its grav.user.groups
which is an array.