Tuesday, November 2, 2010

Modx 2 protected content

Modx default permission setting will redirect user to an unauthorised page when the user did not have permission to view the page.

What if you want to show a teaser of the document?
Here is how:
Create the resource, and do not set the page permission.
Instead, set it to a template which output the resource content by a snippet.

Example template:
[[!out.content? &content=`[[*content]]` &guest=`[[*introtext:empty=`[[*content:ellipsis=`600`:striptags]]`]]` &role=`myrole`]]
This example above will pass in summary of 600 charactors text for guest while output the full content on Logged in with role specified

Example snippet:
$aGroups = $modx->getUserDocGroups(true);
if ($aGroups != null) {
foreach($aGroups as $sGroup) {
if (strtolower(trim($sGroup)) == strtolower(trim($role)) ) {
return $content;

return $guest;

Hope it helps ;)

No comments: