How to limit top level pages by template

Say I want to let the user create it’s own customized about page (top level).

blueprints/about.php
templates/about.php

How to limit to 1 about page per site (or level)?
Ideally disable about template from panel once one has been created.

:grin:

Useful for single instance templates like: home, error, login, register, about, contact, etc. Typically there’s only one of those per site.

As opposed to multiple instances of: article, event, project, etc.

You first have to add the about page:

content/
  about/
    about.txt

On the site.yml blueprint, you can limit the templates the user is allowed to choose from when creating a page.

pages:
  template:
    - default
    - full
    - ...

It is a good practice to specify which templates a parent page accepts, e.g. projects only accepts project template.

Thanks, Pedro. IFAIK that will not limit the number of instances of that page, but only which templates allowed.

You could achieve this with permissions:

<?php
// site/roles/editor.php
return [
  'name'        => 'Editor',
  'default'     => false,
  'permissions' => [
    '*'                 => true,
    'panel.page.create' => function() {

      if($this->state() === 'ui') {
        // always show the add button
        return true;
      }

      if($this->target()->page()->children()->filterBy('intendedTemplate', '==', 'about')->count() > 0 ) {
        return 'A page with this template already exists';
      }

      return true;

    }
  ]
];

Note that you would need to repeat this for every user role and template.

Thank you very much. I’ll give it a try.