Admin: Show user a subset of page templates when creating new page


Until the permissions evolve

on admin, where merge class “Groups” on body → {{ body_classes }} with php plugin
{{ body_classes }} : / grav-plugin-admin / … /templates/partials/base-root.html.twig#L48

Admin v1.7.x > Accounts > Access Levels > Groups

with bodyClassFunc( string/string[] $classes ) ???

Why ?
In css :

  • hide pages in page selection lists
  • Add color groups
  • and more

I can override admin theme
If admin update … :grimacing: :partying_face: :grimacing:

thx for help

Hi @Kit I was wondering if it used in conjunction with the admin panel


for using and overriding controlling some of the display aspects, the one that jumps to mind will be,

default page count
where it reduces how many items are shown in the list

also under pages/advanced you will see a field for body classes, which injects this in to templates, is states for quark at present, so you might just want see if your template supports it

Its quite specific question on Gravs inner workings and might be worth asking on the discord server or logging the question on the getgrav github page, where the developers hang out.

Sorry I cant be more specific

Hi @spamhater

thank you for the reply

discord, I hate it :smiley:
I’ll go to GitHub then, just take the time :wink:

1 Like

@Kit I would suggest you make sure you post your issue in Issues · getgrav/grav-plugin-admin ( rather than general grav github, since its is a specific backend admin enquiry :slight_smile:

@spamhater Yes of course ! :+1:

@Kit, I’m sure you’ve tried to create a clear and succinct as possible question. I’ve read the question several times over the past 7 days, but I’m afraid I still do not understand the questions/issue, nor the desired goal…

Would you mind providing a tad more information to clarify the issue and explaining what you are trying to achieve?

Hi @pamtbaau,
Sorry :disappointed_relieved:

currently, they see all the pages
for all groups

I’m trying to achieve

Add class on body (grav admin plugin)

the user’s group

and with css
.grp_1 #new-page .option[data-value=“form”] {
display: none;


From 11 pages to 3 pages
The user will be less confused by all these options

Once this option is unlocked
We could imagine, one colour per group and more


@Kit, I’ll try to answer my own questions…

Issue: When Admin user creates a new page, a (possibly) large list of templates is shown in the Add Page modal. This might be confusing to the user.

Goal: When Admin user creates a new page, show a brief list of templates where the content of the list depends on a configuration setting.


  • I don’t like the (mis)use of the Groups field for this, since it is being used for setting access permissions on pages. I therefor chose a different approach.
  • I don’t like the idea of adding group-names in css/scss files as class selectors, nor the idea of adding coloured borders around the template select field. I skipped this.

Having said that, I’ve taken the following route to implement the goal as formulated by myself. And that might not be your goal…


  • Add a ‘template’ field to the User blueprint
    • Create file /user/blueprints/user/account.yaml to override existing blueprint and add field 'Templates`.
      Add the following:
        type: account
        context: blueprints://user
          validation: loose
              ordering@: -2
              security@: admin.super
              type: select
              multiple: true
              size: large
              label: Available templates
              data-options@: '\Grav\Common\Page\Pages::pageTypes'
              data-default@: '\Grav\Plugin\Admin\Admin::getLastPageName'
              classes: fancy
              help: Create simple list of templates to be used by user
                type: commalist
  • Create new plugin to alter the template list in modal Add Page:
    • $ bin/plugin devtools new-plugin
    • In generated plugin update function onPluginsInitialized as follows:
      if ($this->isAdmin()) {
            // Put your main events here
            'onAdminPageTypes' => ['onAdminPageTypes', 0],
    • Create function onAdminPageTypes as follows:
      public function onAdminPageTypes(Event $event)
         /** @var User */
         $user = $this->grav['user'];
         if (!$user->get('username')) {
         $allTypes = $event['types'];
         $templates = $user->get('templates', null);
         if (!$templates) {
             // Show user list of all available templates
         $types = [];
         foreach (array_values($templates) as $template) {
             $types[$template] = $allTypes[$template];
         $event['types'] = $types;



  • No changes to Admin
  • No hardcoded group selectors in css/scss
  • A change of Available templates in User config, will only be effective after next login of user.
  • Once page has been created, field Page Template in tab Advanced will still show all available templates. But you didn’t mention that field, so it should be ok…
  • Does it leave room for improvements? It sure does…
1 Like

sorry for the late reply and thank you for this very complete answer
I’ll look into it as soon as possible :wink:


I have just tested it and it works perfectly, many thanks

And above all

  • No changes made to the administrator
  • No hard-coded group selectors in css/scss

I made some improvements to be able to use it on groups and all works.
Why are you going to tell me

Issue : I need to add an option for all users and I need to open them one by one.
If 1-6 users ok,
if more … outch, I’m going to drink coffees :coffee: and come back :smiley:

Goal : To be able to add an option in “Add page” on several users at the same time

Maybe one day we can find it here