How to limit content for specific user roles?

Hi!

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: http://getkirby.com/blog/frontend-authentication

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 http://getkirby.com/docs/solutions/authentication for Kirby 2.x!

1 Like