Toggle a tag when pressing button to reveal text

63 views
Skip to first unread message

Ed Edson

unread,
May 18, 2019, 6:54:42 PM5/18/19
to tiddl...@googlegroups.com
New to TW, this is a basic question but I can't seem to figure it out.

I am using the reveal widget in a way very similar to the example in the docs:

<$reveal type="nomatch" state="$:/state/SampleReveal2" text="show">

<$button set="$:/state/SampleReveal2" setTo="show">Show me</$button>

</$reveal>
<$reveal type="match" state="$:/state/SampleReveal2" text="show">

<$button set="$:/state/SampleReveal2" setTo="hide">Hide me</$button>

! This is the revealed content
And this is some text

</$reveal>

I would like to add a tag to the current tiddler when the text is revealed, and remove it when it is hidden.

Is the a way to modify the above to add this functionality?

Thanks for your help!

TonyM

unread,
May 18, 2019, 8:35:59 PM5/18/19
to TiddlyWiki
A quick answer is to add an action to each button that adds or removes the required tag.

Personaly I prefer setting the reveal state to a value in a field on the current tiddler so as to not over burden the tags.

Regards
Tony

TonyM

unread,
May 18, 2019, 8:55:14 PM5/18/19
to TiddlyWiki
Place these (untested) after the <$button> or the variation within the button definition itself.
Tiddler is not specified making it apply to the currentTiddler

Tag method
<$action-sendmessage $message="tm-add-tag" $param="tagname"/>
or
<$action-sendmessage $message="tm-remove-tag" $param="tagname"/>


Field method
<$action-setfield $field="fieldname" text="show"/>
Or
<$action-setfield $field="fieldname" text="hide"/>

Regards
Tony


On Sunday, May 19, 2019 at 10:35:59 AM UTC+10, TonyM wrote:
A quick answer is to add an action to each button that adds or removes the required tag.

Personally I prefer setting the reveal state to a value in a field on the current tiddler so as to not over burden the tags.

Regards
Tony

Message has been deleted

Ed Edson

unread,
May 18, 2019, 9:36:53 PM5/18/19
to tiddl...@googlegroups.com
Thank you for your reply.

I added the action-sendmessage widget and weirdly it works when I try it in the preview pane but not once I have saved the tiddler...

Here is what I tried in full:

<$reveal type="nomatch" state="$:/state/SampleReveal2" text="show">

<$button set="$:/state/SampleReveal2" setTo="show">
<$action-sendmessage $message="tm-add-tag" $param="tagname"/>
Show me
</$button>

</$reveal>
<$reveal type="match" state="$:/state/SampleReveal2" text="show">

<$button set="$:/state/SampleReveal2" setTo="hide">
<$action-sendmessage $message="tm-remove-tag" $param="tagname"/>
Hide me
</$button>

! This is the revealed content
And this is some text

</$reveal>

TonyM

unread,
May 19, 2019, 2:21:46 AM5/19/19
to TiddlyWiki
Ed,

At first I tried a variation as follows with no luck

<$reveal type="nomatch" state="$:/state/SampleReveal2" text="show">


<$button>
<$action-setfield $tiddler="$:/state/SampleReveal2" $field="text" text="show"/>

<$action-sendmessage $message="tm-add-tag" $param="tagname"/>
Show me
</$button>


</$reveal>
<$reveal type="match" state="$:/state/SampleReveal2" text="show">


<$button>
<$action-setfield $tiddler="$:/state/SampleReveal2" $field="text" text="hide"/>

<$action-sendmessage $message="tm-remove-tag" $param="tagname"/>
Hide me
</$button>


! This is the revealed content
And this is some text


</$reveal>

Then I realise simply wrap the above with https://tiddlywiki.com/#FieldManglerWidget
<$fieldmangler>
Wikitext here
</$fieldmangler>
it now works out of preview mode/ on the view mode.

As will  your original
<$fieldmangler>



<$reveal type="nomatch" state="$:/state/SampleReveal2" text="show">


<$button set="$:/state/SampleReveal2" setTo="show">
<$action-sendmessage $message="tm-add-tag" $param="tagname"/>
Show me
</$button>


</$reveal>
<$reveal type="match" state="$:/state/SampleReveal2" text="show">


<$button set="$:/state/SampleReveal2" setTo="hide">
<$action-sendmessage $message="tm-remove-tag" $param="tagname"/>
Hide me
</$button>


! This is the revealed content
And this is some text


</$reveal>
</$fieldmangler>

I have never being sure when and if we need to use field mangler.

Regards
Tony

Ed Edson

unread,
May 19, 2019, 1:26:13 PM5/19/19
to TiddlyWiki
This is perfect! Thank you!
Reply all
Reply to author
Forward
0 new messages