Forum

Thread tagged as: Problem, Addons, Members

How do I allow for an editor to select a member tag/group to access content

I have built a site using Perch and now need to limit access to certain areas of a page based upon the visitors member tag. User will be either blank (no tag) or girton or westwick. Editors do not create new pages but may create either a gallery, text item, list or image to an existing page. I would like for the editor to also select Blank, Girotn or Westick for who will be allowed access to the relevant peice of content.

My diagnostics are:


Perch: 2.8.29, PHP: 5.6.24, MySQL: 5.5.50-MariaDB, with PDO Server OS: Linux, cgi-fcgi Installed apps: content (2.8.29), assets (2.8.29), categories (2.8.29), perch_gallery (2.8.6), perch_members (1.5) App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_members', 'perch_gallery', ); PERCH_LOGINPATH: /pct PERCH_PATH: /home/hp3-linc1-nfs1-w/219/334219/user/htdocs/pct PERCH_CORE: /home/hp3-linc1-nfs1-w/219/334219/user/htdocs/pct/core PERCH_RESFILEPATH: /home/hp3-linc1-nfs1-w/219/334219/user/htdocs/pct/resources Image manipulation: GD PHP limits: Max upload 20M, Max POST 20M, Memory: 64M, Total max file upload: 20M F1: 2edba60ed1f613d6dd804feb202456a2 Resource folder writeable: Yes SCRIPT_NAME: /pct/core/settings/diagnostics/index.php REQUEST_URI: /pct/core/settings/diagnostics/ DOCUMENT_ROOT: /home/hp3-linc1-nfs1-w/219/334219/user/htdocs HTTP_HOST: www.scallywagsdaynursery.com

The page content is called in via the template

<perch:blocks>
  <perch:block type="text" label="Text">
    <perch:content id="caption" type="textarea" label="Paragraph" editor="ckeditor" html="true"/>
  </perch:block>

<perch:block type="slug" label="Bulleted list">
<perch:repeater id="list" label="Bulletd List" max="10">
<perch:before>
<ul>
</perch:before>
<li>
      <perch:content id="listitem" type="text" />

</li>
<perch:after>
</ul>
</perch:after>
</perch:repeater>
  </perch:block>

  <perch:block type="image" label="image">
    <img src="<perch:content type="image" id="image" />" alt="<perch:content type="text" id="alt" label="Description" required="true" title="true" />" class="photo"/>
  </perch:block>

</perch:blocks>

A page currently shows as https://prntscr.com/ej282c. I would like for each item to ask which member tag it is relevant to.

I have a similiar ruling on a gallery page already with

<?php if (perch_member_has_tag('girton')) {
          perch_gallery_album_details('girton');
          perch_gallery_album_images("girton", array('template'=>'album-grid.html')); } ?>

However again I would prefer the creation of the content and the member tag selection to be done by the editor and then the template says

if member_tag == "same as in the page editor selector" then show else ""

I hope that all makes sense and any help appreciated.

Alan Isaacson

Alan Isaacson 0 points

  • 4 years ago

In the page settings there is a setting for Restrict access to members with tags

Hi Robert Thanks for the reply. I have looked at the logics. I can restrict the entire page to a specific group but ideally I would like to say that each content block on a page is selected by the editor. So if the editor adds 3 text blocks each one can have a seperate member group allocated to it or leave it blank to be seen by all.

Text block 1 = everyone Text block 2 = girton Text block 3 = everyone

Hope that helps to clarify

Thanks in advance

Drew McLellan

Drew McLellan 2638 points
Perch Support

So do you want to do this dynamically? As in specify the permissions at the same time as entering the content?

Hi Drew,

Sorry for the delay. Yes I would like to specify dynamically at the point of adding the content block which member group is allowed to see it.

Thanks in advance

Alan

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not aware of a good workflow for that currently.

Hi,

This may not work, but could you use the in-template conditionals for this (see second example on this page):

https://docs.grabaperch.com/addons/members/examples/tags/

So something like:

<perch:if exists="member_tag">
<perch:member has-tag="<perch:content id="member_tag" type="select" label="Choose a Member tag to restrict this content to"
options="Girton|girton,Westick|westick" allowempty="true" />">
</perch:if>
<!-- The rest of your template -->
<perch:if exists="member_tag">
</perch:member>
</perch:if>

Not tried this so may be nonsense but I think it may work?

Hi Mike and Drew,

Thank you both for your help. I think I am close now. My template is now set as

<perch:blocks>
<perch:if exists="member_tag">
<perch:member has-tag="<perch:content id="member_tag" type="select" label="Choose a Member tag to restrict this content to"
options="Girton|girton,Westick|westick" allowempty="true" />">
</perch:if>
  <perch:block type="text" label="Text">
    <perch:content id="caption" type="textarea" label="Paragraph" editor="ckeditor" html="true"/>
<perch:if exists="member_tag">
</perch:member>
</perch:if>
  </perch:block>


<perch:block type="slug" label="Bulleted list">
<perch:repeater id="list" label="Bulletd List" max="10">
<perch:before>
<ul>
</perch:before>
<li>      
      <perch:content id="listitem" type="text" />

</li>
<perch:after>
</ul>
</perch:after>
</perch:repeater>
  </perch:block>

    <perch:block type="image" label="image">
    <img src="<perch:content type="image" id="image" />" alt="<perch:content type="text" id="alt" label="Description" required="true" title="true" />" class="photo"/> 
  </perch:block>

</perch:blocks>

My page editor then sees this, the red arrows are the new member group selector. The blue arrows are to add the additonal Perch blocks to a page.
Screenshot

I have tried the code on all seperate Perch: Block tags and also around the entire page, however the end result from the code above is as Screenshot 2 As you can see all content is then visible. Any further help much appreciated as I have a very upset client waiting for this. Alternatively do you know if it is possible to insert the relevant security tags via the CK editor? Many thanks in advance