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
Rate this solution
If you think this solution is useful — rate it up!
I looking for a code hide contents from anonymous visitor or non-registered user. But as well show that content to registered users.
When I use this in the sidebar I get the following displayed in the final rendered page. Any ideas on why this might occur?
Here is the sidebar code:
Of course… as soon as I post this I answer my own question ;-)
Can't include the module NewPage.
NoNo: [[module NewPage size="15" button="new page" category="wiki"]]
Works as expected without this.
Thanks!
SUO snippet generates [[div]] as an intermediate output. That is a problem if you want to put it inside a list (a quite common wanted use) or inline, because Wikidot converts a [[div]] into:
Would it be possible to modify the snippet to use [[span]] instead of [[div]]?. Wich are the drawbacks of it?. See Problems with Divs.
Stumbled across this looking for a way to hide/block users from certain forums but I'm pretty new to wikidot and I'm not sure if it can work that way. Any thoughts or suggestions?
Shucks, just when I thought I had a convenient scapegoat on which to blame all of my problems.
Thanks for the info.
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?
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.
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.
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
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:
Community Admin
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.
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
At the time of this post (405 days after the birth of SUO), there are 216 pages on Wikidot using this technology!
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
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
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!
With the new fix, you can just type %%created_by_unix%% for in code use
See My Sites
The Drawing Board
reviewit
Yes, I'm stupid =D
Your words, not mine :)
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)