By tsangk
Description
This snippets allows "conditional blocks" to be added to wiki pages. It checks for the two variables provided and if they are matching (or not matching), the content will be shown. Nesting within modules only work in advanced mode (see below). Thanks to James Kanjo for his awesome SUO snippet where I stole some of the front-end and back-end include coding.
Syntax
Basic
attribute | required | values | default | use |
---|---|---|---|---|
type | yes | equal or notequal | none, required | sets the type condition (testing for equal values or non-equal values |
unique | no | any string | singlemode | for multiple condition blocks to be included into a single wiki page |
var1 | no | any string or Wikidot variable | 1 | one of the variables or values to be tested in the block |
var2 | no | any string or Wikidot variable | 1 | one of the variables or values to be tested in the block |
Use in a data form template:
[[include :snippets:if START |unique=1|type=equal|var1=%%form_data{agree}%%|var2=iagree]]
You have agreed to the Terms and Conditions of the site.
[[include :snippets:if END]]
Advanced
Two separate components must be used with this. One outside a module, the other may be nested within a module.
:snippets:if-adv (PREPARE)
attribute | required | values | default | use |
---|---|---|---|---|
unique | no | any string | singlemode | a string to match the separate components |
var1 | no | any string or Wikidot variable | 1 | the string that will be tested against in the nested component (var2 |
:snippets:if-adv-nest (START and END)
attribute | required | values | default | use |
---|---|---|---|---|
type | yes | equal or notequal | none, required | sets the type condition (testing for equal values or non-equal values |
unique | no | any string | singlemode | this must match the unique id you used for the "prepare" block |
var2 | no | any string or Wikidot variable | 1 | the variable which will be tested against the string defined as var1 in PREPARE. |
Similar to James' SUO - but only for one person
[[include :snippets:if-adv PREPARE |var1=tsangk]]
[[module ListUsers users="."]]
[[include :snippets:if-adv-nest START|type=equal|var2=%%name%%]]
[/code:conditional-blocks/edit/true Edit this snippet!]
[[include :snippets:if-adv-nest END]]
[[/module]]
[[include :snippets:if-adv PREPARE |unique=1|var1=tsangk]]
[[module ListUsers users="."]]
[[include :snippets:if-adv-nest START|unique=1|type=notequal|var2=%%name%%]]
Hi %%name%%, you're not tsangk!
[[include :snippets:if-adv-nest END]]
[[/module]]
In action
Advanced
Similar to James' SUO - but only for one person
[[include :snippets:if-adv PREPARE |unique=advanced-eg|var1=tsangk]]
[[module ListUsers users="."]]
[[include :snippets:if-adv-nest START|type=equal|unique=advanced-eg|var2=%%name%%]]
[/code:conditional-blocks/edit/true Edit this snippet!]
[[include :snippets:if-adv-nest END]]
[[/module]]
[[module ListUsers users="."]]
[[include :snippets:if-adv-nest START|type=notequal|unique=advanced-eg|var2=%%name%%]]
Hi %%name%%, you're not tsangk!
[[include :snippets:if-adv-nest END]]
[[/module]]
would render:
Notes
- For Conditional Blocks to work inside modules, use the advanced version.
- Unfortunately, variables with spaces will not work in this snippet :(
in Action-live
on the code:_template this is inserted:
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 tsangk
URL Title with Slash Redirect - 04 Jan 2018 11:32
404 (Page does not exist) Redirect - 20 Nov 2012 11:40
Custom HTML Blocks - 25 Oct 2012 11:30
Syntax Highlighter - 16 Feb 2012 01:45
Rate this solution
If you think this solution is useful — rate it up!
Hi Tsangk…
Imagen I want to use this on only one page, and also to better understand what you're doing… Would it be possible to give the code without the includes on one page…
A - S I M P L E - P L A N by ARTiZEN a startingpoint for simple wikidot solutions.
This is basically how it works:
[[module CSS]]
.if-equal-default{ display: none; }
.if-equal-VAR1{ display: block !important; }
[[/module]]
[[div class="if-equal-default if-equal-VAR2"]]
Hide content unless VAR1 = VAR2
[[/div]]
By default, the DIV block is hidden by the first statement .if-equal-default{ display: none; }. However, in the case when VAR1 = VAR2, the second line in the CSS module is matched, so the previous statement is overrided. The !important is actually redundant there, as CSS is processed line-by-line.
Let's say VAR1 was apple and VAR2 was banana, the code would render:
[[module CSS]]
.if-equal-default{ display: none; }
.if-equal-apple{ display: block !important; }
[[/module]]
[[div class="if-equal-default if-equal-banana"]]
APPLES ONLY!
[[/div]]
Therefore, the div won't be shown as by default (set by if-equal-default class), the div is not displayed.
Kenneth Tsang (@jxeeno)
Yes that is what I assumed it would be like… but what I am trying to understand is how did you get the var1 (apple) into the module listpages… that's what I'm after.
Have a look at http://feedback.wikidot.com/wish:780 … because you seemed to manage this
Have a look at http://community.wikidot.com/forum/t-462190/include-with-variable-acting-strange#post-1419497 because you seemed to manage this
A - S I M P L E - P L A N by ARTiZEN a startingpoint for simple wikidot solutions.
"Advanced….One inside outside a module, the other may be nested with a module."
Sorry, the English here doesn't make sense. Must it be inside or must it be outside? I assume it's outside.
Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.
Fixed. Is it clearer now?
Kenneth Tsang (@jxeeno)
Yes thanks. Now off to try it :)
Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.
Hi Kenneth,
Thanks again for the idea to use James Idea for such conditional comparisons!
I think it is time to write a new "blog" entry on the community-news about this snippet!
It works ..
Regards
Helmut
Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.
Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?
I would - but don't have the time. I have a few assignments I have to complete - and they are very time consuming :S
Kenneth Tsang (@jxeeno)
Thanks James :D
Kenneth Tsang (@jxeeno)
You credit me too much!
I'm glad my SUO helped you build this framework :)
The clever thing about SUO was that you use the same include for the opening and closing code blocks via neglecting attributes in the closing block. Whilst the backend coding is compleximicated to manufacture, it makes coding for the end-user easier.
What a great snippet tsangk ! It's going to be part of fantastic applications, never before possible!
I echo James' comments: great work which I look forward to implementing.
Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.
I'll add another echo to the chamber. This looks really cool and I'm also looking forward to giving it a spin.
Thanks Kenneth!
Community Admin
Sorry, but the template text is now ncouded in all your snippets….!
Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.
Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?
Thanks Helmuti ~!
Kenneth Tsang (@jxeeno)
You can always change to the %%fullname%% for action-live to show the inlcude only here…
ok - i changed it to the one selected page only :
[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
@@
Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.
Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?
It's fine. I don't mind it :D
Kenneth Tsang (@jxeeno)
You might also want to make bind the code in "code blocks":
text above inserted with:
Kenneth Tsang (@jxeeno)
Hi Shane and Helmuti! Thanks for checking my new snippet out!
I just updated the documentation with a nestable version. It's experimental and may be unstable - but check it out!
@Helmuti: would it be better to include the horizontal rule in within the conditional block:
EDIT: Oh.. you fixed it… nevermind :D
Kenneth Tsang (@jxeeno)
I inserted.
This results only in a source coding in the rendered output:
<div class="if-equal-1-formdata-hide if-equal-1-tsangk">
<p><strong><span style="color: red;">Thanks to tsangk for this great snippet:</span></strong> <a href="/code:conditional-blocks">conditional-blocks</a></p>
</div>
The css module inserted fpor Author: [[*user tsangk]]{ !!
Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.
Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?
I've achieved this result before with CSS (with some help from Bryce, possibly… I forget) — but this is simpler to put into a page. Nice work!
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)