Pages
Page Blueprint
Let's say we are creating a website for a membership program that provides access to various courses. After subscribing, members can access the courses. In order to determine whether a user with a specific subscription plan can access a particular course, we need to define the required access criteria for each course. This can be done by adding a field to the page blueprint where we can set the necessary gates.
title: Course
fields:
gates:
extends: fields/gates/plans
# or extends: fields/klub/gates/plans
text:
label: Content
type: textarea
The field's default key is "gates," but it can be changed in the config files.
Setting Gates in the Panel
Once you have defined subscription plans in Stripe and provided the Stripe credentials in the Klub plugin config file, you will be able to select them in the Panel field of the course page.

The Klub plugin uses a cache to improve performance and reduce the number of calls to the Stripe API. However, please note that any changes made in Stripe may not immediately be reflected in the Panel.
Instead of using subscription plans to restrict page access, one-time payments with Stripe products could be used instead.
Checking Gates in PHP
You can use the klub()
-helper function to check if a user is allowed or disallowed to access a certain object based on the gates it has defined.
if (klub()->allows(kirby()->user(), $page->gates())) {
// ...
}
if (klub()->disallows(kirby()->user(), $page->gates())) {
// ...
}
or even shorter
if ($page->isAllowed()) {
// ...
}
if ($page->isNotAllowed()) {
// ...
}
Let's assume you want to redirect a user from a course lesson to the parent course page if the user has no access to the course. We will also display the course content on that course page or let the member know it has no access. We only have set gates on the course, not each lesson.
<?php
if ($page->isNotAllowed()) {
go($page->parent()->url());
}
// otherwise display lesson
<?php snippet('klub/allows', slots: true) ?>
<?php slot('isAllowed') ?>
<p>Allowed, display the content</p>
<?php endslot() ?>
<?php slot('isNotAllowed') ?>
<p>Not Allowed, render CTAs</p>
<?php endslot() ?>
<?php endsnippet() ?>
The klub/allows
-The snippet uses the current user and current page object by default, but you set them manually using the data array of the snippet function.
Instead of using the klub/allows
-snippet with its slots, we could have used calls to klub()->allows($page)
and an if-else-clause.
if ($page->isAllowed()) {
echo "Allowed";
} else {
echo "Not Allowed";
}
Pages Collections
$allowedLessons = page('courses')->children()->listed()->removeNotAllowed();