For a non-developer, is there a simple way to test whether a user is in a particular user group? I want to hide a "Subscribe" link from users who are already subscribers ...
It is easy to do this test for anonymous users:
[[If? &operator=`EQ` &operand=`(anonymous)` &subject=`[[+modx.user.username]]` &then=`CONTENT HERE`]]
But the documentation at
http://rtfm.modx.com/display/revolution20/Users says that this test can only be applied for usernames and IDs.
David Walker
Principal, Shorewalker DMS
Phone: 03 8899 7790
Mobile: 0407 133 020
There is an ismember output modifier, but the most efficient way is a simple snippet:
Put the subscribe link in a chunk called Subscribe.
Put this where the link goes:
[[!ShowSubscribeLinkHere]]
Create a snippet called ShowSubscribeLinkHere with this code:
<?php
/* ShowSubscribeLinkHere snippet */
$output = "";
if (!$modx->user->isMember('Subscribers')) {
$output = $modx->getChunk('Subscribe');
}
return $output;
Not working for me yet. Probably my fault.
David Walker
Principal, Shorewalker DMS
Phone: 03 8899 7790
Mobile: 0407 133 020
Quote from: shorewalker at Jul 09, 2011, 09:29 AM
Not working for me yet. Probably my fault.
More likely mine. There was a typo in the code (corrected above). Watch out for case-sensitivity in the snippet and chunk names also.
Thanks BobRay. I saw the misplaced quote marks and corrected them. I consistently get a 500 Internal Server Error when I place the snippet in the page. Checked and rechecked, and now driving me nuts ...
David Walker
Principal, Shorewalker DMS
Phone: 03 8899 7790
Mobile: 0407 133 020
I was having similar problems last night with this bit of code
<?php
$output = $modx->user->isMember($group) ? $modx->getChunk($yesChunk) : $modx->getChunk($noChunk);
return $output;
?>
I found out that it was a problem being logged in as an admin. Try using another browser without being logged into the manager.
DropboxUploader -- Upload files to a Dropbox account.
DIG -- Dynamic Image Generator
gus -- Google URL Shortener
makeQR -- Uses google chart api to make QR codes.
MODxTweeter -- Update your twitter status on publish.
OK, solved it by fixing one more typo. So the code to display info only to non-subscribers, where subscribers are members of the user group "Subscriber", is as follows:
<?php
/* ShowSubscribeLinkHere snippet */
$output = "";
if (!$modx->user->isMember('Subscribers')) {
$output = $modx->getChunk('Subscribe');
}
return $output;
If you’re building a subscription site, the most obvious use of this is to display content asking non-subscribers to subscribe.
Big thanks to BobRay for this.
David Walker
Principal, Shorewalker DMS
Phone: 03 8899 7790
Mobile: 0407 133 020
Glad it worked (finally). Sorry about the typos.
BTW, if you want it to be even faster, you can skip the chunk and put the link text directly in the snippet:
<?php
/* ShowSubscribeLinkHere snippet */
$output = "";
if (!$modx->user->isMember('Subscribers')) {
$output = '<a href="url/of/subscribe/page">Subscribe</a>';
}
return $output;
BTW, is the MODx community going to hold some sort of virtual party for BobRay’s 10,000th post? It’s coming up soon, and it seems like it should be honored somehow. I’ve only been involved for a few weeks, but it’s obvious he’s made one hell of a contribution ...
Or we could just send money:
http://bobsguides.com/support-this-site.html.
David Walker
Principal, Shorewalker DMS
Phone: 03 8899 7790
Mobile: 0407 133 020
I'm buying the book.. The guys a great evangelist for modx...