Description
You can utilize a combination of iftags and set-tags in order to create a toggle tag button, one that will add a tag to the page if it isn't already there or remove it if it is. The amount of code for this can be slightly unwieldy and difficult to read, however:
[[iftags _hidden]][[button tags -_hidden text="Unhide"]][[/iftags]][[iftags -_hidden]][[button tags +_hidden text="Hide"]][[/iftags]]
So… why not make this easier?
[[include :snippets:toggletag |tag=_hidden |add=Hide |remove=Unhide]]
Syntax
Attribute | Default | Description |
---|---|---|
tag | _deleted | The tag you want the button to add/remove |
add | Delete | The button's text when adding the tag |
remove | Undelete | The button's text when removing the tag |
inline | @@ | If TRUE, allows for this Snippet to be used inline. |
Code
[[include :snippets:toggletag |tag= |add= |remove= ]]
In order to make the code work inline, you need to pass TRUE to the inline attribute, like in the following example:
[[include :snippets:toggletag |tag=_hidden |add=Hide |remove=Unhide |inline=true]]
[!----] | \
[[include :snippets:toggletag |tag=_deleted |add=Delete |remove=Undelete |inline=TRUE]]
If you supply none of the attributes, then the toggle tag for _deleted will automatically be implemented.
In action
You can see a quick example of this snippet here.
Note: As iftags statements cannot be nested, you cannot use this snippet within another iftags body.
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 Timothy Foster
Fancy HR Dividers - 07 Apr 2021 06:23
Carousel - 24 May 2015 01:18
Modal Image - 01 May 2015 17:20
Bootstrap Image Box - 19 Jul 2014 01:27
Togglecheck - 17 Dec 2013 20:27
Alternative Specific Users Only - 11 Dec 2013 18:04
Image Box - 10 Dec 2013 03:14
Hide Tags - 14 Feb 2013 21:35
Plurality Checker - 16 Jul 2012 03:21
Mini Chat Area - 15 May 2012 12:04
Table Alterations - 16 Feb 2012 01:45
Rate this solution
If you think this solution is useful — rate it up!
Ah, I see where I was mistaken now! The problem is that iftags cannot be nested. Since I have iftags surrounding the content portions on the _template page, putting them on the regular page means I am actually putting one iftags inside another; therefore, it is not interpreted. I created a new section (%%content{4}%%) which lies outside all iftags, and it works like it does on your site.
Wow, I had been mistaken about this for a very long time probably because so many of the pages I make extensively use the iftags condition on the _template page. Thanks for the correction; I've changed the documentation appropriately.
Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me
I amde a test on my test site on some pages:
http://helmuti-pdorf.wikidot.com/iftags-test1
and the iftags is working fine on single or included pages too!
On your test page you have one problem included by your used "_template" page:
(see the code down)
The "norma"l content of your page is not shown because of the tags "_ null" is not set…
( and the content 1 or 2 is not shown because of no divider between contents is set on the iftags-test page
I tried some mtags setting and I have to say - I am a little confused now by the usage of whoch content is now shpen or not.
But without _template page ( or the usage if the iftags to limit the shown content) the iftags is working fine.
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 ?
Well, when I try to use iftags on this sandbox page, it simply returns the blocks as pure text. From my experience, iftags can only be placed on live _template pages and within ListPages modules with separate="true". I believe this is actually the intended behavior and that the documentation is worded incorrectly, but it may indeed be a bug. Admittedly, it would be convenient for iftags to work on standalone pages; it ought to only add to flexibility (:
Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me
Hi Timothy!
I have a questin to this code. on doc:wiki-syntac#iftag there is the sentence:
On this page you have extra inserted the notice:
Is this really true ( a bug?) or is it only important to know in connection in using the snippet code here
I can remember I used iftags on my test sites often on single pages , long before live templates were living.
and in ListPages too ( than testing the red pages).
PS: Sorry for the inserted explanation on the example page…. :)
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 ?