Hi All,
Just a simple snippet to display a "Welcome username, Logout" if user is logged in, or "Login" if no user is currently logged in.
Usage like so:
[!WebLoginBox &Loginpage=`id` &Welcomemsg=`Welcome ` !]
Where id is the login page id (your user login form).
could do this with template var I guess, im not too sure which is more efficient yet.
is this one different from the personalize snippet ?
the login form itself has the word login above the form text only (no link) the form itself i’m assuming replaces the need for the link
it sounds like the webloginbox snippet produces a login: logout text links but so far i’ve only seen one text link logout
is this the way the snippet is suppose to work only 1 text link ?
-
MODX Staff
- 12,272 Posts
ahhh... it’s exactly what personalize does i think...
Ryan Thrash, MODX Co-Founder
Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
-
☆ A M B ☆
- 24,524 Posts
If you put the "personalize" snippet at the beginning of your page (or template), you can use the placeholders anywhere you want, including in the chunk you use for the WebLogin form.
<!-- log out hyperlink section -->
<span id="logout">Welcome, [+uid+] | <a href='[+action+]'>[+logouttext+]</a></span>
The [+uid+] placeholder is from the Personalize snippet.
You can use it again in your document:
<h2>[*longtitle*], [+uid+]!</h2>
I put the snippet in the head of my template:
[!Personalize?ph=`uid`&guest=`Guest`!]
</head>
<body>
the "ph" option causes it to output to a placeholder named as you specify. Otherwise, it would behave as a regular snippet and only output to the location where it’s called.
I don’t suppose someone would be willing to help me set this up? I’ve tried and failed and I would like to get this working.
Any help would be appreciated.
Quote from: sottwell at Mar 31, 2006, 12:18 AM
I put the snippet in the head of my template:
[!Personalize?ph=`uid`&guest=`Guest`!]
</head>
<body>
the "ph" option causes it to output to a placeholder named as you specify. Otherwise, it would behave as a regular snippet and only output to the location where it’s called.
so in your example, what would the name of the placeholder be [guest] ?
is the personalize text only suppose to appear when a user is logged in, I notice it being there long after being logged out even after clearing the browser so wasn’t sure.
-
☆ A M B ☆
- 24,524 Posts
No. The placeholder would be [+uid+] in the case shown above. You specify the placeholder name in the "&ph=`whatever`" option. The "&guest=`Guest`" is to indicate what you want to display as a username for a guest (not logged in) user. You could specify "Visitor" or whatever.
The snippet itself only returns the name itself, whether the username or the name you specified as "guest" user. For example, I have "Welcome, [+uid+]" as a header (actually it’s [*longtitle*], [+uid+] but the longtitle for my home page happens to be Welcome). So it will always say "Welcome, ", only the name will vary. It takes the name directly from the SESSION variable, and if the webusername is not set returns the &guest value instead.
This is an example of an active snippet, whose value is subject to change, so it must be called in the uncached style, [!...!].
starting to make some sense
i have not seen any &ph or &guest in the personalize snippet, where is it that we define &ph ?
i see this at the end
# do the work
$o = ’Guest’; <--typed in guest here
$test = $modx->getLoginUserName();
$o = ($test)? "$w1$message$test$w2" : ’’;
if (isset($ph)) {
$modx->setPlaceholder($ph,$o);
} else {
return $o;
}
-
☆ A M B ☆
- 24,524 Posts
Sorry, I had forgotten that I had added that little feature to it.
$test = $modx->getLoginUserName();
if(isset($guest)) { // add a feature to allow setting a guest username
$test = (!$test) ? $guest : $test;
}
If the username is not set, then it will use the "guest" variable you can specify in the snippt call. If neither is set, it returns an empty string as before.
The &ph in the snippet tag is atomatically converted to a php variable $ph. This is the case with all options in snippet tags.