Userrole based site.yml

Hey.

I’m trying to load a based on a user role a site.yml (site/blueprints/site.yml)
Maybe I’m doing something wrong? But my test user in this role see the normal site.yml
My code:

site/plugins/role-blueprints/index.php

<?php

if(($user = kirby()->user()) && $user->role()->name() === 'coach') {
    $dir = __DIR__ . '/blueprints/pages/roles/site-coach.yml';
} else {
    $dir = __DIR__ . '/blueprints/site.yml';
}

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

site/blueprints/users/coach.yml

title: Coach

site/blueprints/pages/roles/site-coach.yml

title: Site

columns:
  - width: 1/3
    sections:
      pages:
        headline: Pages
        type: pages
        templates:
          - ressourcen
        sortable: true

storage/accounts/pOfj83Wh/index.php

<?php

return [
    'email' => 'test@test.com',
    'language' => 'de',
    'name' => 'Coach',
    'role' => 'Coach'
];

Have you removed the site.yml from /site/blueprints?

Guessing from your post on discord, you put your blueprints in the wrong folder.

You have to put them inside the plugin folder, not inside /site/blueprints.

Please guys, this is really a waste of time of you always post in two places without any references.

2 Likes

Why removing?

I have one in
$dir = DIR . ‘/blueprints/site.yml’;
and one in
$dir = DIR . ‘/blueprints/pages/roles/site-coach.yml’;

Do i miss there somehting?

Bildschirmfoto 2022-09-08 um 14.31.45
Bildschirmfoto 2022-09-08 um 14.33.14

I tried - don’t work for me.

if(($user = kirby()->user()) && $user->role()->name() === 'coach') {
    $dir = __DIR__ . '/blueprints/site-coach.yml';

} else {
    $dir = __DIR__ . '/blueprints/site.yml';
}

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

Bildschirmfoto 2022-09-08 um 14.41.28

Also that don’t work for me
Bildschirmfoto 2022-09-08 um 14.42.37

Ah now it is working.
I put both in the plugin folder :slight_smile: @luca thanks for the hint