How to limit content for specific user roles?


I am new to kirby, and trying to get user roles working with kirby. I managed to set up different roles in the config. I understand, how to call different parts for different roles via this code:

<?php if($user = $site->user() and $user->hasRole('client-a')): ?>
This part of the page is only visible for 
clients with the role client-a
<?php endif ?>

Now, I want to set the visibility of an article by role in the project.txt file. (in the folder “content”)
How do I achieve that? Is there some tag I can call, similar to “Title:” or “Text:” ?

    Title: Some title
    Text: Some text
    Tags: bla
    Role: client-a, admin

Can someone point me into the right direction?

Thanks a lot!

1 Like

As a first step you can use the split()-method to convert a field with a comma-separated list to an array:

$roles = $page->role()->split(',');

This article could also be interesting for you:

1 Like

Yes! =D
This article is exactly what I was looking for. Perfect!
Thank you @flokosiol

The blog in the following article is very old:

You should look at for Kirby 2.x!

1 Like