Attention! This is deprecated: Personalize 2.0 was added to the Repository with new functions. Go to Personalize 2.0 page for further info!
Simple hack of "Personalize" by Ryan Thrash: takes 2 chunks as params, an display one (yesChunk) to LOGGED users and the other (noChunk) to those unlogged.
Useful to display a "Register if you want..." to unregistered users.
I appreciate links to pages using it (just to see it in motion). If noone complains after a week, I’ll add it to the repository.
#::::::::::::::::::::::::::::::::::::::::
# Snippet Name: LoggedOrNot
# Short Desc: calls a chunk if the user is logged in, otherwise calls another
# Version: 1.0
# Created By: kudo ([email protected]), almost totally based on
# Personalize, by Ryan Thrash ([email protected])
#
# Date: July 19, 2006
#
# Changelog:
# Jul 19, 06 -- initial release
#
#::::::::::::::::::::::::::::::::::::::::
# Description:
# Checks to see if webusers are logged in and displays yesChunk if the user
# is logged or noChunk if user is not logged. Insert only the chunk name as
# param, without {{}}.
# Only meant to be used once per page.
#
#
# Params:
# &yesChunk [string] [REQUIRED]
# Output for LOGGED users
#
# &noChunk [string] [REQUIRED]
# Output for NOT logged users
#
#
#
# Example Usage:
#
# [[LoggedOrNot? &yesChunk=`Link` &noChunk=`Register`]]
#
# Having Chunks named {{Link}} and another {{Register}}, the first will be
# published to registered user, the second to non-registered users.
#
#::::::::::::::::::::::::::::::::::::::::
# prepare params and variables
$o = '';
$yesChunk = (isset($yesChunk))? $yesChunk : '';
$noChunk = (isset($noChunk))? $noChunk : '';
# do the work
$test = $modx->getLoginUserName();
if ($test) {
$o = $modx->getChunk($yesChunk);
} else {
$o = $modx->getChunk($noChunk);
}
return $o;
PS: next version will have option to use snippets as output.