Jump to content

Users with specific role as checkboxes


bramwolf
 Share

Recommended Posts

Hey Guys!

I might completely miss something but I really can't figure this one out, here's what I want to do:

I have a repeater that allows the client to create new news items, but not all items should be available

for all users, so I want to tag which users can see the post. 

At first I created a few check boxes whose's names correspond to the users I want to give access.

But for this to work I have to create a checkbox field for each user, and this isn't compatible with

the users my client might add in the future.

So, what I'm looking for is a way to list users with a specific role inside each repeater item and make

them selectable, with for instance check boxes, or a drop down that allows multiple selections.

Any ideas of how I should go about achieving this?

Thanks in advance :)

Bram

Link to comment
Share on other sites

Sounds like you just need a page field that is linked to the users template. Let us know if you need any help setting it up.

These settings for the page field should do the trick - in particular note the Label Field set to "name". Of course if you want checkboxes change ASM Select to checkboxes. It really depends on how many users there are and how many will likely be selected as to which will be better.

post-985-0-52224500-1432214987_thumb.png

  • Like 2
Link to comment
Share on other sites

Awesooommeee! :D

Thanks man! That was precicely what I was looking for, never thought to look for that under a page field :)

I created this like shown above with an extra selector to get users with a specific role. Now on the frond end,

how do I go about checking these values?

something like this?

[ sketch programming -> not actual language ;) ]

foreach ($page->tags as $tag) {

     if ($user->name == $tag->name) {

            if ($tag->value == 1 ) {

                 Show news item

            }

      }

{

something like this?

thanx!

Gr,

Bram

  • Like 1
Link to comment
Share on other sites

I would do it like this:

foreach ($page->tags as $tag) {
    if($tag->allowed_users->has($user)) {
        //show news item
    }
}

That assumes your page field that is linked to users is called "allowed_users".

PS Sorry I forgot about the role issue when setting up the page field selector, but glad you sorted it out!

  • Like 2
Link to comment
Share on other sites

I would do it like this:

foreach ($page->tags as $tag) {
    if($tag->allowed_users->has($user)) {
        //show news item
    }
}

That assumes your page field that is linked to users is called "allowed_users".

PS Sorry I forgot about the role issue when setting up the page field selector, but glad you sorted it out!

Yes! That's it :) Much better than my original thought :) Thanks for your help!

Bram

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...