Search code examples
modx-revolution

How to show/hide html elements based on a modx user's group membership


How can I show or hide html elements based on a modx user's group membership?

For example I have an edit button and a view button on a given page, I want users who have permission to access the edit resource to be able to see the button while it should be hidden from all other users.

UPDATE I wound up writing a little thing to get the job done:

call snippet getButton

[[!getButton? &rid =`20` &btn=`ButtonEditTpl` &qs=`contract_id=[[!+contract_id]]`]]

The snippet

<?php
    $btn = isset($btn) ? $btn : null;

    $qs = isset($qs) ? $qs : 'this=that';

    $rid = isset($rid) ? $rid : 0;

    $output = '';

    $resource = $modx->getObject('modResource',$rid);

    if($resource){

      $url = $modx->makeUrl($rid, '', $qs);

      $output = $modx->getChunk($btn,array('url' => $url));

    }

    return $output;
?>

Solution

  • Just use Personalize snippet http://bobsguides.com/personalize-tutorial.html

    [[!Personalize?
        &yesChunk=`@CODE:<p>Place for your button</p>`
        &noChunk=`@CODE:<p>You are not logged in</p>`
        &allowedGroups=`MembersOnly,Managers`
    ]]