Forum

Thread tagged as: Question, Members

Client wants to create members

I'm a bit of a members app newbie so forgive me if this is a daft question…

My client would like to create members. Can I do this with a multiple item region (in Perch, rather than a collection in Runway), where each member is an item in the region? Each member would then log in and only see their item's content. Is that possible?

Thanks,

Martin.

Martin Underhill

Martin Underhill 5 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to create the members themselves inside the Members app.

Once you've done that you can tag content and tag members, and then only display when the tags match.

Ah, cool. So if I make an editable slug based on the title of the member item, they can copy that into the member's profile in the member's app as a tag. Thanks :)

I'm doing this in my template:

<perch:content id="client" type="text" label="Client name" required="true" title="true" />
<perch:content id="slug" type="slug" for="client" editable="true" label="Client tag" required="true" help="Add this tag to any members you want to have access to this client’s files" suppress="true" />

<perch:member has-tag="<perch:content id="slug" type="slug" for="client" />">
  test
</perch:member>

It's not outputting 'test' if the slug matches the member's tag though. Guess it's because I'm not allowed to nest perch:content tags. How do I get it to set the slug/tag match on a per-member basis?

I guess what I'm asking is: is there a way to pass the value of id="slug" into the has-tag attribute?

I've just tried this tack, but it's (probably unsurprisingly) not working:

Set values:

<perch:content id="client" type="text" label="Client name" required="true" title="true" suppress="true" />
<perch:content id="slug" type="slug" for="client" editable="true" label="Client tag" required="true" help="Add this tag to any members you want to have access to this client’s files" suppress="true" />

pull slug out of the first template and pass it into second template:

  if (perch_member_logged_in()) {
    perch_content_create('Clients', [
      'template'  => 'client_detail.html',
      'multiple'  => true,
      'edit-mode' => 'listdetail',
    ]);
    perch_content_custom('Clients', [
      'template' => 'client_detail.html',
    ]);
    $client = perch_content_custom('Clients', [
      'filter'        => 'slug',
      'match'         => 'eq',
      'value'         => perch_get('s'),
      'skip-template' => 'true',
      'return-html'   => 'true',
    ]);
    $slug = $client['0']['slug'];
    PerchSystem::set_var('tag', 'slug');
    perch_content_custom('Clients', [
      'template' => 'client_detail_output.html',
    ]);

Output the variable in the second template:

<perch:member has-tag="tag">
  <perch:content id="client" type="text" />
<perch:else:member />
  Nope
</perch:member>
Drew McLellan

Drew McLellan 2638 points
Perch Support

The perch:member tags get parsed before perch:content tags, so that won't work.

To make it dynamic like that, you'll need to test in the page, and then either conditionally show the region, or pass a var into the template that you can use to test whether parts of the template should be displayed.

I've had a delve and I think this sort of thing is what I'm looking to do:

 $memberTagsModel = new PerchMembers_Tags;
  $userTags = array();
  foreach ($memberTagsModel->get_for_member(perch_member_get('memberID')) as $tag) {
    $userTags[] = $tag;
  }
  PerchSystem::set_var('userTags', $userTags);

Then

<perch:every userTags as userTag>
  <perch:member has-tag="userTag">
    <perch:content id="client" type="text" />
  <perch:else:member />
    Nope
  </perch:member>
</perch:every>

But that won't work as it's not proper perch syntax. What do you think I should do?

I've got another system where I have to add the clients for my client like this:

      $clients = array(
        'Client one',
        'Client two',
        'Client three',
        'Client four',
        'Client five',
      );

      function outputClient($client){
        $url = PerchUtil::urlify($client);
        perch_content_create($client, array(
          'template'=>'file.html',
          'multiple' => true,
          'searchable' => false,
          'edit-mode' => 'listdetail',
        ));
        PerchSystem::set_var('clientName', $client);
        perch_content_create($client . ' uploads', array(
          'template'=>'client_upload_form.html',
          'roles'=>'Admin',
          'searchable' => false,
        ));
        if (perch_member_has_tag($url)) {
          echo '<h2>' . $client . '</h2>';
          perch_content($client);
          PerchSystem::set_var('clientName', $client);
          perch_content_custom($client . ' uploads', array(
            'template'=>'client_upload_form.html'
          ));
        };
      }

      foreach($clients as $client){
        outputClient($client);
      }

But I really need to keep out of the loop on this one as the client who this new project is for will be adding loads of their clients to the members area.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You shouldn't need to do that at all. In the simplest terms, what are you trying to do?

Haha yeah, maybe I'm overcomplicating things :) I'd like my client to add an item to a region and to take the slug from that region and assign it as a tag to a member, so that that member can see that item's content when they log in

Drew McLellan

Drew McLellan 2638 points
Perch Support

So both the tags on the content and the tags on the member are essentially unknown?

That's right

Drew McLellan

Drew McLellan 2638 points
Perch Support

And the region contains multiple items, some which might match the user's tags, and some that might not?

That's right – so a user can only see their company's content

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think they way to do this might be to use an each callback to test the tags

perch_content_custom('Clients', [
      'template' => 'client_detail.html',
      'each' => function($item) {
         if (perch_member_has_tags('...etc')) {
             $item['display'] = true;
         }
         return $item;
      },
    ]);

Hi Drew, got it! Here's what I'm doing:

  perch_content_custom('Clients', [
    'template' => 'client_detail.html',
    'each' => function($item) {
       if (perch_member_has_tag($item['slug'])) {
           $item['display'] = true;
       }
       return $item;
    },
  ]);

and then <perch:if exists="display" > in the template to show the content of the item.

Thanks very much :)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Great!