Where to put the blueprint templates: property

Hi everybody,
for the creation of a new (sub-)page, I’d like to have the appropriate templates in a particular order for the end user’s convenience. At the same time, templates that are irrelevant for the end user, should be filtered out. In the blueprint site.yml, I employ the following code:

title: Site
preset: pages
unlisted: true
templates:
  - overview
  - detail
  - list
  - section
  - main

This works very fine as intended. But having this on the site level, also the admin suffers from the template filtering.

Where do I have to put that templates: property so that it does not affect the admin account but only everyone else?

Thanks in advance for helping. You’re doing an awesome job!

What do you mean? What is the admin supposed to see?

There is no way to set these properties by user role. The only way to achieve this would be separate site.yml blueprints per user role, see Going beyond Kirby's permissions features | Kirby CMS

@texnixe Thanks for replying that fast at this time of the year! :smiley:

There are more templates than those mentioned in my post, partly because they are not used yet, partly because the customer will not need them. But the customer in the role of the end user wants to evaluate intermediate statuses. (We agreed on this, so he can see what he is about to get and say more precisely what he expects during development. He could not do this before, because he is not an IT native and not able to structure his wishes, so it is iterating. Sigh.)

Therefore the necessity of filtering. The sorting is necessary in order to help him to choose the right template when creating new pages (new products, e.g.) because the default alphabetic ordering is by no means adequate.

I skimmed over the documentation of your suggestion Going beyond Kirby's permissions features | Kirby CMS. It says:

This implementation registers blueprints in a plugin, for example, a custom home.yml for clients, and a general home.yml for all other user roles.
:
Possible downsides
You have to maintain multiple blueprints for a page type.

Only pages blueprints are mentioned, so does that work too only for the site.yml?
What am I supposed to enter in the snippet for the ??? ?

<?php
if(($user = kirby()->user()) && $user->role()->name() === 'admin') {
    $dir = __DIR__ . '/blueprints/admin-site.yml';
} else {
    $dir = __DIR__ . '/blueprints/site.yml';
}
Kirby::plugin('cookbook/role-blueprints', [
    'blueprints' => [
        '???/site' => $dir
    ]
]);

Would that in fact require a complete doubling of all blueprints? Would this perhaps have the same or a similar effect as mentioned in Going beyond Kirby's permissions features | Kirby CMS ?

I did not anticipate that it was that complicated.

1 Like

@texnixe Thanks a lot, I’ll try this immedately.

You only need to duplicate the blueprints where you need different templates.

Come to think of it, I wonder if we could even do this on the section level, instead of for whole blueprints.

Thanks for your help so far. At the moment, I am stuck with integrating the solution into the index.php. Alas I have to leave right now and will be back after 3 p.m. So I’ll keep you informed.

I tested my idea from above just to be sure and it works as expected, so instead of creating blueprints for pages or the site based on user role, the same can be done for section blueprints.

Although I just noticed that you are using a pages blueprint preset instead of defining the sections manually. In that case, it doesn’t make sense, of course, and you would have to stick with defining the two site.yml files in your plugin.

Note that if you do this, you have to remove the standard site.yml from the /blueprints folder, because files in this folder overwrite what you define in the plugin.

It works!

Thank you very much, @texnixe, for the rapid and thorough help of yours. Here my final solution which now works exactly as intended:

$blueprintDir        = kirby()->root() . "/site/blueprints";
$adminSiteBlueprint  = "$blueprintDir/site-admin.yml";
$clientSiteBlueprint = "$blueprintDir/site-client.yml";

if (($user = kirby()->user()) && $user->role()->name() === 'admin') {
    $site_yml = $adminSiteBlueprint;
} else {
    $site_yml = $clientSiteBlueprint;
}

Kirby::plugin('dwc/role-blueprints', [
    'blueprints' => [
        'site' => $site_yml
    ]
]); 

This is my index.php in the plugin directory. Note however that I prefer to have the site blueprints under the standard directory for all blueprints (site/blueprints), and not in the plugin directory. Of course, there is no more site.yml in this directory.

Many thanks, have a beautiful rest of this year and a successful fresh start into 2021. Same goes for the rest of your team! :clap:

1 Like

Thank you very much! We can but hope that 2021 will bring around some change for the better.

All the best to you and your loved ones!

I pretty much regret to have to re-open this issue. The plugin solution described earlier does exactly what it is supposed to do.

Unfortunately, this only affects the outermost level of the page hierarchy. As soon as I step one level deeper, creating a sub-page of an existing page, the template select box again shows all available templates in a pretty much random order.

This is no longer the question whether this affects the admin user or not. I tried to employ those templates: options in blueprints for the sub-pages, but to no avail. Seems to me that it only gets honored in the *-site.yml files.

Which options do I have to control which templates can and should be used for sub-pages of a particular existing page?

The allowed templates are defined with the template options in the pages section, in this case in the parent blueprint.

Perfect. Thank you.