Can you set a viewable permission to a collection

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.

How I ended up creating the code was to create a home page

{% for child in collection %}
    {% include 'slide.html.twig' with {'blog': page, 'page': child, 'truncate': true} %}
{% endfor %}

with slide child pages that contain within the front matter the following

allowedGroups:
   - project1

then create a user with a group of project1

if the slide group equals a user group it displays the slide else does nothing

{% if config.plugins.login.enabled and grav.user.username %}
    {% for slideGroup in page.header.allowedGroups %}
    {# <p>slideGroup: {{ slideGroup }} </p> #}
        {% for userGroup in grav.user.groups  %}
        {# <p>userGroup: {{ userGroup }} </p> #}
            {% if userGroup == slideGroup %}
                {% include 'partials/slide-item.html.twig' %}
            {% else %}
                {# <p> FALSE </p> #}
            {% endif %}
        {% endfor %}
    {% endfor %}
{% endif %}

i also added that if a user is not logged in it will display demo slides instead
these have no allowed groups added to the slide page

{% if config.plugins.login.enabled and not grav.user.username %}
    {% if page.header.allowedGroups is empty %}
        {% include 'partials/slide-item.html.twig' %}
    {% endif %}
{% endif %}

hope it helps someone, Thanks for the help!

@dean_007, Maybe I don’t exactly understand your problem and solution, but it seems you are creating child pages for the home page solely to add a user group to its frontmatter and show an image based on that user group.

Instead of looping through a collection of child pages containing the user group inside their frontmatter, why not add the user group to the metafile of each image and loop to the images of the home page and read the user group in their metafile?

See Metafiles