Toggle Tag

By Timothy FosterTimothy Foster


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]]


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.


[[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!

rating: +4+x
Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License