This question has been answered by multiple community members. See the first response.
if ($modx->user->isMember('somegroup')) { $output = $modx->getChunk('chunk1'); } else { $output = $modx->getChunk('chunk2'); } return $output;
<?php /* [[!showContentIfUserGroup? &mustBeUserGroup=`some user group` &input=`Hello World`]] Must have &input and &mustBeUserGroup defined. If you want to show the &input to multiple User Groups, seperate the User Groups with a comma (but don't have a space following the comma). Example: User Group 1,User Group 2,User Group3 I don't know how you would be able to have the ` in the &input. */ $output = ''; if($input != '' && $mustBeUserGroup != '') { //uncomment for testing //$holdx = $mustBeUserGroup; if(strpos($mustBeUserGroup, ',') !== false) $mustBeUserGroup = explode( ',', $mustBeUserGroup ); if ($modx->user->isMember($mustBeUserGroup) ) $output = $input; else { //uncomment for testing //$output = 'user not in '. $holdx; } } else { //uncomment for testing //$output = '&input or &mustBeUserGroup were empty in showContentIfUserGroup snippet call'; } return $output;
[[!showContentIfUserGroup? &mustBeUserGroup=`some user group` &input=`[[$chunkName]]`]]
[[!showContentIfUserGroup? &mustBeUserGroup=`some user group` &input=`chunkName`]]
$userGroup = $modx->getOption('mustBeUserGroup', $scriptProperties, 'nogroup', true); $chunk = $modx->getOption('chunkName', $scriptProperties, '', true); if ($modx->user->isMember($userGroup)) { return $modx->getChunk($chunk); } return '';
$output = ''; if ($modx->user->isMember('group1')) { $output = 'chunk1'; } elseif ($modx->user->isMember('group2')) { $output = 'chunk2'; } elseif ($modx->user->isMember('group3')) { $output = 'chunk3'; } return $output;
<?php /* [[!showContentIfUserGroup? &mustBeUserGroup=`some user group` &input=`Hello World`]] only one or the other, not both &input and &chunkName [[!showContentIfUserGroup? &mustBeUserGroup=`some user group` &chunkName=`chunk name`]] Must have either &input or &chunkName AND then &mustBeUserGroup defined. If you want to show the &input to multiple User Groups, seperate the User Groups with a comma (but don't have a space following the comma). Example: User Group 1,User Group 2,User Group3 I don't know how you would be able to have the ` (back tick) in the &input. */ $output = ''; $input = $modx->getOption('input', $scriptProperties, '', true); $chunkName = $modx->getOption('chunkName', $scriptProperties, '', true); $mustBeUserGroup = $modx->getOption('mustBeUserGroup', $scriptProperties, '', true); if($chunkName != '') { $chunk = $modx->getChunk($chunkName); $input = $chunk; } if($input != '') { if($mustBeUserGroup != '') { //uncomment for testing //$holdx = $mustBeUserGroup; if(strpos($mustBeUserGroup, ',') !== false) $mustBeUserGroup = explode( ',', $mustBeUserGroup ); if ($modx->user->isMember($mustBeUserGroup) ) $output = $input; else { //uncomment for testing //$output = 'user not in '. $holdx; } } else { //uncomment for testing //$output = '&mustBeUserGroup was empty in showContentIfUserGroup snippet call'; } } else { //uncomment for testing //$output = '&input or &chunkName were empty in showContentIfUserGroup snippet call'; } return $output;
$output = $input;
$output = $modx->getChunk($chunkName);
<?php /* Snippet: showContentIfUserGroup [[!showContentIfUserGroup? &mustBeUserGroup=`some user group` &input=`Hello World`]] only one or the other, not both &input and &chunkName if snippet call has both &input and &chunkName declared, the &chunkName will show and not the &input [[!showContentIfUserGroup? &mustBeUserGroup=`some user group` &chunkName=`chunk_name`]] Must have either &input or &chunkName AND ALSO &mustBeUserGroup defined. If you want to show the &input to multiple User Groups, seperate the User Groups with a comma (but don't have a space following the comma). Example: User Group 1,User Group 2,User Group3 I don't know how you would be able to have the ` (back tick) in the &input. */ $output = ''; $input = $modx->getOption('input', $scriptProperties, '', true); $chunkName = $modx->getOption('chunkName', $scriptProperties, '', true); $mustBeUserGroup = $modx->getOption('mustBeUserGroup', $scriptProperties, '', true); if($mustBeUserGroup != '') { if($input != '' || $chunkName != '') { //uncomment for testing //$holdx = $mustBeUserGroup; if(strpos($mustBeUserGroup, ',') !== false) $mustBeUserGroup = explode( ',', $mustBeUserGroup ); if($modx->user->isMember($mustBeUserGroup) ) { if($chunkName != '') { $chunk = $modx->getChunk($chunkName); $input = $chunk; } if($input != '') $output = $input; } else { //uncomment for testing //$output = 'user not in '. $holdx; } } else { //uncomment for testing //$output = '&input or &chunkName were empty in showContentIfUserGroup snippet call'; } } else { //uncomment for testing //$output = '&mustBeUserGroup was empty in showContentIfUserGroup snippet call'; } return $output;