ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Custom Member Fields as Conditional

February 25, 2011 5:48pm

Subscribe [5]
  • #1 / Feb 25, 2011 5:48pm

    DigitalDesigns

    94 posts

    We are using the most recent version of User and have added a custom member field with an id of “people-groups”

    We would like to control how content is displayed in our expression engine template based on this field.

    What is the correct way to call a custom member field and use it as a conditional variable within a template?

    This is the code currently not working:

    {if logged_in_people-groups == 'Amasai"}
                    <li class="{switch="||end"}">
                        <h4>{title} <a href="#">i</a></h4>
    <p>                    <div class="profile"><br />
                            {about_staff_title}<br />
                        </div><br />
                        {about_image}<br />
                    </li><br />
    {/if}

    Moved to CodeShare Corner by Moderator

  • #2 / Feb 25, 2011 6:12pm

    Mark Bowen

    12637 posts

    Is the code above inside the Custom Profile Data Tag and is logged_in_people-groups the name of the field?

    For the conditional to work the code would need to be within the Profile Data Tag.

    Best wishes,

    Mark

  • #3 / Feb 27, 2011 3:09pm

    Greg Salt

    3988 posts

    Hi DigitalDesigns,

    As Mark has asked, is this code inside the Custom Profile Data tag? I’m a little unclear how this relates to the User module, can you clarify that?

    Cheers

    Greg

    @Mark, thanks for the help.

  • #4 / Feb 28, 2011 12:05pm

    DigitalDesigns

    94 posts

    Sorry about the confusion. We realize that our code is not accurate - we are just speculating and have not been able to get it to work. We would like to be able to display data based on a custom member field that the user is associated with.

    For Example:

    We have created a custom member field that contains a “select list” (called “member-color”) that we have given the three options of “blue”, “green”, and “yellow”.

    We have also classified (categorized) the data with a category called “color” and made the same three options (although we know they cannot be related, we are trying to use this as a “work-around”).

    In the template, we are trying to stipulate that when a user logs in, and their custom member field “member-color” matches the criteria of “blue”, the data categorized as “blue” would display - but none of the others (unless the data is also classified as blue).

    It is our hope that we can use this method to create a “ACL” of sorts…but realize that it requires a conditional code that identifies IF the custom member field matches certain criteria THEN display content that matches certain category filters.

    Ideas/Thoughts/Help?

  • #5 / Mar 01, 2011 2:58am

    John Henry Donovan

    12339 posts

    DigitalDesigns,

    You could use a bit of PHP

    <?php
    $memberColor = "{exp:member:custom_profile_data}{member-color}{/exp:member:custom_profile_data}";
    echo $memberColor;
    ?>


    Now you can use PHP conditionals to filter content

  • #6 / Mar 01, 2011 2:24pm

    DigitalDesigns

    94 posts

    So in the example above, can you give me a “for instance” (remember..this is somewhat new for us) that would conditionally display the channel content if it matches the code?

    Such as - On a page:

    ***
    Channel Content here (publicly visible)

    (conditional php code here - that would display the following content IF the member custom profile tag is “blue”)
    - Channel Content Classified as “Blue”
    (end php code)

    More channel content here (publicly visible)
    ***

    *On a side note, we realize that this is not a method of “securing the data” only a work-around filtering the display of content 😊

    We SO MUCH appreciate your help on this!

  • #7 / Mar 01, 2011 3:02pm

    Mark Bowen

    12637 posts

    Try this. It’s not perfect by any means and a Plugin might serve you better here but this may help to get you started on your path.

    Main Template

    {exp:member:custom_profile_data}
    
    
    {exp:query sql="
                    SELECT cat_id
                    FROM exp_categories
                    WHERE cat_name = '{member-color}'
                    AND group_id = '1'
                    "}
    
    {embed="test/colours-final" category="{cat_id}"}
    
    {/exp:query}
    
    
    {/exp:member:custom_profile_data}

    Embedded Template - tests/colours-final

    {exp:channel:entries channel="test" category="{embed:category}"}
    {title}
    
    {/exp:channel:entries}

    Hopefully that should help you get what you need. You will need to change the group_id=‘1’ part in the query so that it reflects the ID of your category group but hopefully then that should work.

    Please bear in mind this was written without even testing so hopefully I’ve got all the syntax right there.

    Best wishes,

    Mark

  • #8 / Mar 01, 2011 3:11pm

    Mark Bowen

    12637 posts

    Actually thinking about this some more, the code above should work (again not tested but pretty sure it should) however if you can wait until tomorrow some time then I can rewrite it as using the Custom Profile Data tags just to bring back one fields value is probably overkill here. It will mean either a slightly more complex query or some PHP but it may well bring down the processing on the page a bit.

    Personally I don’t think it would be a major hit on the server doing things this way so perhaps you could test it out and check with your profiler to see if it’s worthwhile using or whether a leaner version would be better and let me know.

    Hope that all helps a bit.

    Best wishes,

    Mark

  • #9 / Mar 01, 2011 4:32pm

    DigitalDesigns

    94 posts

    Absolutely we can wait…  As far as using a plugin, we have looked EXTENSIVELY, and this was the best method we could come up with to create a “ACL” of sorts.

    We are HOPING that by utilizing categorization of content, and classification of users (then “associating” them through the conditional code), we can create some sort of display “filter”.  Of course this does not LIMIT user access, only display… 

    At some point we hope that there is someone out there creating an ACL add-in for EE that will allow us to create “security groups” and assign users/multiple users to the security group, and assign a security group to content (not just a channel, but down to the channel entry level) thus creating access control for an individual entry….That would be HUGE!!

    Thanks for you help!!!

  • #10 / Mar 01, 2011 5:35pm

    Mark Bowen

    12637 posts

    Did you try out the code I attached above? 😉

    Should do what you need and as I don’t have access to your exact environment I was suggesting that you perhaps run it in situ and test to see if it has any impact at all. I’m guessing in this case it would probably minimal in which case you wouldn’t need the longer SQL query.

    Perhaps give the code above a go first and let us know how it goes?

    Best wishes,

    Mark

    P.S. There was an extension for 1.x called Entry Permissions which allowed for member groups permissions per entry but I’m not sure if the author has or will update that for 2.0

  • #11 / Mar 02, 2011 11:59am

    Sue Crocker

    26054 posts

    Hi, DigitalDesigns. This topic is better served as a CodeShare Corner topic, so moving there.

  • #12 / Mar 02, 2011 2:28pm

    DigitalDesigns

    94 posts

    Mark -

    We’ve tried and tried, but to no success.

    To clarify:

    Members are classified using a Custom Member Field (CMF) entitled “security level” (a multi-select field that admin classifies the user as one type)

    The template needs to filter:

    1. First it needs to determine if the user is logged in
    2. Next it needs to determine which one of the security levels the user is associated with
    3. Then we need to use a conditional statement (If CMF == ‘High Security’)
    4. Then we would put in the regular expression engine display tags…

    In this manner, the first two items (most likely SQL queries) determine WHO is logged in, then our conditional (step 3) identifies the criteria for what displays (item 4)

    My guess is that item 3 and item 4 would repeat with different security levels until all are identified (covering all classifications of users)

    It is within step 4 that we would identify the categorization of the content…

    Make sense?  I believe the code earlier in the thread selected the content first, rather than the user…right?

  • #13 / Mar 02, 2011 3:52pm

    Mark Bowen

    12637 posts

    I’ve got to admit I’m a little confused now as in this post you said you were working with a colour drop down?

    Which is it, colour or security level?

  • #14 / Mar 02, 2011 4:09pm

    DigitalDesigns

    94 posts

    Sorry - we were using “color” as an example for a CMF classification - but the concept would be used in the same manner.

    Unless CMF matches (whether the user is classified as ‘high’ or ‘blue’), then the content would not be displayed.

  • #15 / Mar 02, 2011 4:49pm

    Mark Bowen

    12637 posts

    Well if you have pretty much the exact same setup as you previously mentioned then all you’d need to do is change {member-color} in the code I showed above to the name of your custom profile field that holds the security level and also change (if required) the group_id (again if required) to reflect your category group.

    As long as the options in both the custom profile field (security field) match the category names in your weblog / channel exactly then the code above should definitely work.

    Best wishes,

    Mark

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases