By James Kanjo
Description
A common request amongst Wikidot users is the ability to show or hide data based on the person who is viewing your wiki. For example, if a wiki administrator is viewing the wiki, then s/he should be able to see options such as “Manage Site”, “Edit Side Bar” and “Change CSS”. Perhaps you have decided that particular members of a wiki should not see certain options in the sidebar, such as welcome links for new visitors on a site.
The Specific Users Only Include makes this easy.
Syntax
| attribute | required | allowed values | default | description |
|---|---|---|---|---|
| type | yes | showto or hidefrom | none (it must be manually entered) | This specifies the type of SUO Include you wish to use. You can show data to the specified users, or you can hide data from specific users. |
| unique | no | alphanumeric characters, hyphens and underscores | universal | For the use of multiple SUO Includes on a single page (each one will need a unique identifier) |
| user | no | A Wikidot user's UNIX name | none | This means lowercase letters, with spaces separated by hyphens. You can find this by clicking on a user's avatar, and taking note of their “profile page” link. |
| user0 | … | … | … | Same as above, but for when applying SUO data to multiple users |
| user1 | … | … | … | … |
| … | … | … | … | … |
| user99 | … | … | … | Currently supports up to 101 users |
| mode | no | default or advanced | default | For using advanced variables, such as %%created_by%%, as a user |
The syntax is to use the SUO include with its attributes, followed by your Wikidot code on a new line, then by the SUO include again (but with NO attributes).
Code
[[include :snippets:suo BEGIN CODE |unique=first |type=showto |user1=james-kanjo |user2=michal-frackowiak]]
**Hello James Kanjo & Michał Frąckowiak!!!**
[[include :snippets:suo END CODE]]
[[include :snippets:suo BEGIN CODE |unique=second |type=hidefrom |user1=james-kanjo |user2=michal-frackowiak]]
**Hello Everybody Else!!!**
[[include :snippets:suo END CODE]]
In action
Important
Because the framework of this include is based upon the ListUsers Module, certain limitations apply:
- The use of Modules inside the SUO code is prohibited
- Anonymous Users will see nothing, because the ListUsers Module doesn't display data to anonymous users
- When in “Advanced Mode”, as the advanced mode utilises the ListPages Module, it cannot be nested inside the ListPages module (and cannot be included by a ListPages module)
In terms of having a NewPage module as part of your SUO code, a working alternative is the Extended NewPage Module in “Manual Mode”.
Thanks to tsangk for this great snippet: conditional-blocks
text above inserted with:
[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]
Other snippets posted by James Kanjo
Per Category CSS Module - 06 Mar 2012 03:38
Video Player - 16 Feb 2012 01:50
Remove Duplications - 16 Feb 2012 01:39
RegExp Date Wizard - 16 Feb 2012 01:39
"Random Page!" link - 16 Feb 2012 01:35
Quoted Blockquotes - 16 Feb 2012 01:33
NewPage Button - 16 Feb 2012 01:26
MP3 Player - 16 Feb 2012 01:25
JavaScript Addition - 16 Feb 2012 01:14
iframe Redirect - 16 Feb 2012 01:09
iframe embed - 16 Feb 2012 01:08
Extended NewPage Module - 15 Feb 2012 00:50
Random Page - 18 May 2011 09:50
Redirect - 11 Feb 2010 10:00
Rate this solution
If you think this solution is useful — rate it up!






I am using this code in a private page of mine, and I see both … any idea why? :S
Edit: Code posted here: http://sandbox.wikidot.com/james-kanjo-suo-test:page (same result, I see both). If this works as you say it does, I am truly impressed. So far I can't get it working properly though :(
Edit2: It seems that if I use this code, I see neither. So the second one is taking precedence?
Edit3: Just to confirm for you… it is working perfectly fine in the example you have posted on this page. All I see is Hello Everybody Else!!!
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
Hmm. It means you've found a hole in my programming… :(
Working on a fix right now…
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
Have posted a few updates to that comment, please check to see the other test I did :)
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
@ Edit 2, If you see neither, that's fantastic, and it's working as it should… look at the code you posted here
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
Whoops, lol. Good point.
If I add my name to the first one, I see only the first one, so that works fine. :)
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
Fixed with a new functionality: the unique attribute.
Thanks for pointing this out Shane!!! I'm ashamed as a programmer to not have seen it coming *hides embarrassment*
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
I as a programmer understand how hard it is to find these bugs - it always helps to have a second set of eyes. So not sure why you're embarrassed xD
Will test it with the new attribute and post here if it doesn't work. So if I don't reply again today… it's probably because it works 100% fine and I'm too busy having fun with it :P
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
Sweet!
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
Actually, I will post ;-) Works perfectly fine now!
Quick question — is there a limit to the number of user names I can provide? Is it ten (user1 - user10) or eleven (user + user1 - user10), or unlimited (user1 … user99) ?
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
The current limit is 12:
I can add a lot more users at request though.
Glad to hear you like it!
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
I love it! People on my site have been requesting this for ages and I can finally give it to them!
New announcement posted so they know about it: http://cyclods.wikidot.com/thread:84
Not going to give the code to use it though, as I don't want them to use 'hidefrom' to hide something from me :P So will just be used on the non-editable pages (e.g. homepage).
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
Haha! That's great!
I just added support for 101 users now (user, then from user0 to user99)
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
Thanks!
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
Not to nit-pick, but users 0-99 only adds up to 100 users, not 101. Or, am I missing something?
Thanks for increasing the limit. I will be able to make good use of this.
Is there some clever way to create a page that has a group of users and then call that page's content inside the include? I'm thinking something like this:
That way I could maintain a list of users on the pages in the mygroup category and not have to chase down every occurrence of the include if my list of users changes.
-Ed
Free Wikidot Applications · Your Shared Photo Gallery · Your Personal Blog
Yes, 0-99 only adds up to 100 users. But James didn't say that. He said:
I can count 101 there.
user
user0
user1
user2
…
user99
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
OK, I didn't read it carefully. The docs and examples are a little confusing. Do we use user for just single users and user0-99 for multiples, or can we use something like:
In other words, do we have to use the user, user0-99 sequentially? I suppose I should just go do some testing! (or study the source) xD
-Ed
Free Wikidot Applications · Your Shared Photo Gallery · Your Personal Blog
James,
I was just looking at the code and found a small bug/typo.
The semicolon in the {$hidefrom} line is in the wrong place. I tried to edit it, but I don't have permission. It seems to be "non-fatal" since the !important may not be required, but it is a good safety measure.
-Ed
Free Wikidot Applications · Your Shared Photo Gallery · Your Personal Blog
Yes, the whole reason I had !important was as a safety measure… but it's not a very good safety measure if it's outside the semi-column!!! Thanks Ed!
Do you need to use things sequentially? No, you can be as illogical as you want to be =P
I just added the “user=” option for programming aesthetics if I'm applying stuff to only one person.
Now grouping users… That's an interesting idea! I'll think about a design to implement that.
Thanks for the support guys! I'm glad you like it =D
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
Is there any way to use this to show it to only the page creator? I tried user=%%created_by%% but it doesn't seem to work, even when the name is already in lowercase (e.g. my own name) nothing appears.
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
Remember bug 16? That's the reason nothing is appearing.
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
=(
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
I found a workaround!
Check it out!
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
Yes, I'm stupid =D
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
Your words, not mine :)
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
With the new fix, you can just type %%created_by_unix%% for in code use
See My Sites
The Drawing Board
reviewit
At the time of this post (405 days after the birth of SUO), there are 216 pages on Wikidot using this technology!
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
Is that all?
We need to spread the word!
There are currently 8,893,011 pages at Wikidot. SUO deserves to be on at least half of those… surely! XD
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
I know! Apparently people would rather have MP3 Players on their sites than to show things to specific users… what's going on?!
Actually, something made my day the other day — the Wikidot team are using SUO in the feedback site! I'm so happy!
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
I am using SUO in a live template to selectively display an email address field to only site admins and moderators. The problem is that I can't get the form data to display the contents of the field - it just displays the variable. Is this a bug or a limitation of using form data with SUO?
This code works in the live template when it's outside of the SUO snippet, but doesn't when it's inside the SUO wrapper.
Here's the source of the page:
Free Wikidot Applications · Your Shared Photo Gallery · Your Personal Blog
Unfortunately, that's a limitation. The SUO module is based on the ListUsers module, which only allows the following:
Other variables are ignored.
It's just like other modules (think of ListPages within a live template) - you can use variables as part of the module's parameters (e.g. perPage="%%form_raw{field}%%" should work), but if you try to put it inside the module body it becomes out of scope of the live template - it's in scope of the ListPages module instead.
As far as I understand, the same thing is happening here… the variable is in scope of the SUO (ListUsers) module, not the live template.
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.
Hey James,
Firstly thanks for this cracking snippet, it's really right up my street, but alas I've encountered a problem:
I've got several instances of this snippet at the top of the sidebar on my site all in default mode and all working perfectly. However, further down my sidebar I have a separate listpages module and several instances of the countpages module.
Now, despite my SUO snippets using only the listusers syntax (indeed, I've manually specified default mode for each of them), they stop both the listpages and countpages modules from updating for varying lengths of time (an hour to over a day's worth). The information they show remains the same even after I make new pages that should show up on or affect the data those modules display.
I tried removing it quickly to double check it was definitely the problem, and both sets of modules instantly updated themselves…
Having checked the "Important" segment of the documentation numerous times there seems to be no mention of such occurrences in default mode and nothing at all for the countpages module.
I've checked your code, and there's nothing wrong with it.
It sounds like a Wikidot caching issue… Let me ask, is the updating issue with the CountPages module only, by any chance?
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
Well, that's what I thought too, it just seemed like a fantastic coincidence for it to suddenly change when I removed the code and checked.
Edit: Especially since I've always kept a close eye on the goings on of the sidebar and I've never had this problem until I started using the SUO snippet.
Both the ListPages and CountPages modules fail to update.
Hmm, odd. I've created a bug report, hopefully something should get resolved soon.
λ James Kanjo
Blog | Wikidot Expert | λ and Proud
Web Developer | HTML | CSS | JavaScript
Sadly the problem has progressed further:
Now occasionally when I save a page after editing it, it'll revert back to a previous iteration/save of the page.
In my case, I have two page layouts, an old one and a new one. After updating a page from the old layout to the new one and hitting save there's a good chance it'll show the old layout prior to my editing it (which is remarkably different to the new one, there's no mixing them up). I have to refresh the page once or twice to get it to behave.
To further compound the issue, when I start editing pages after refreshing them in such a manner they occasionally show the wiki code from a previous iteration using the old layout, despite me having completely rewritten it since. This happens regardless of whether the old layout or the new layout is showing.
*Pulls out hair*
Edit: It goes without saying that neither of these problems happened even once prior to the implementation of this code, not in over 2.5 years.
I've heard of similar things happening to other users before (and I think it may have happened to me as well). It's a Wikidot bug.
If you post what you just told us on http://feedback.wikidot.com as a bug report, they should be able to fix it.
Shane Smith ★ Website: Wikidot Development & Programming. ★ STE Wikidot Editor: Windows. Mac. Linux. ★ Twitter. Google+.