[TW5] help creating slider-like macro

191 views
Skip to first unread message

jess

unread,
Dec 7, 2014, 1:53:49 PM12/7/14
to tiddl...@googlegroups.com
Hi all,

Total TW/TW5 newbie here, slowly learning and tweaking. I've read quite a few posts in this group, and from what I can tell you all are a very helpful and newbie-friendly bunch, so I'm hoping someone may have some pointers for me. :)

I'd like to create a macro similar to the slider-macro, where a reader can click a button/link and have additional text (pulled from another tiddler via transclude) revealed. The catch is, I'd like to define where in the containing tiddler that text should appear. For example:

(title) Containing tiddler

This is a paragraph in the containing tiddler that contains the _link_ to reveal the child tiddler. This is some more text to fill up the paragraph.

> This is where I want the child tiddler to appear.

This is a second paragraph in the containing tiddler.


I currently have it working without custom macros as follows:

This is a paragraph in the containing tiddler that contains the
<$reveal type="nomatch" state="$:/revealstate" text="show">
<$button set="$:/SampleRevealState2" setTo="show" class="btn-invisible btn-link">link</$button>
</
$reveal><$reveal type="match" state="$:/revealstate" text="show">
<$button set="$:/SampleRevealState2" setTo="hide" class="btn-invisible btn-link">link</$button></$reveal> to reveal the child tiddler. This is some more text to fill up the paragraph.

<$reveal type="nomatch" state="$:/revealstate" text="show">
</$reveal>
<$reveal type="match" state="$:/
revealstate" text="show">
{{child tiddler}}
</$reveal>

This is a second paragraph in the containing tiddler.

Ideally, there'd be a way to write a macro to accomplish the same, perhaps with syntax similar to the following:
This is a paragraph in the containing tiddler that contains the <<revealmacro "link">> to reveal the child tiddler. This is some more text to fill up the paragraph.

<<revealmacro "{{child tiddler}}">>

This is a second paragraph in the containing tiddler.


Unfortunately, I'm computer-literate enough to cut, paste, and sometimes tweak... but I'm fairly clueless as to how writing a new macro would work.

Any ideas?  Thanks so much in advance!

-jess

Stephan Hradek

unread,
Dec 7, 2014, 2:26:11 PM12/7/14
to tiddl...@googlegroups.com
Does this help?

\define reveallink(link, state)
<$reveal type="nomatch" state="$state$" text="show">
 
<$button set="$state$" setTo="show" class="btn-invisible btn-link">
    $link$
 
</$button>
</
$reveal>
<$reveal type="match" state="$state$" text="show">
 
<$button set="$state$" setTo="hide" class="btn-invisible btn-link">
    $link$
 
</$button>
</
$reveal>
\end

\define revealtiddler(childtiddler, state) <$reveal type="match" state="$state$" text="show">$childtiddler$</$reveal>



Used like this:

This is a paragraph in the containing tiddler that contains the
<<reveallink "link" "$:/temp/SampleState">> to reveal the child tiddler. This is some more text to fill up the paragraph.

<<revealtiddler "{{child tiddler}}" "$:/temp/SampleState">>




jess

unread,
Dec 7, 2014, 9:23:46 PM12/7/14
to tiddl...@googlegroups.com
That works exactly as I'd hoped, Stefan, thank you! (btw, it was your great site that got me as far as I'd gotten initially, so thanks for that as well!)

jess

unread,
Dec 7, 2014, 9:25:05 PM12/7/14
to tiddl...@googlegroups.com
Sorry, I mis-spelled your name, I see it should be Stephan. Thank you again for the assistance!
Message has been deleted

jess

unread,
Dec 7, 2014, 11:07:05 PM12/7/14
to tiddl...@googlegroups.com
Gah, typo in last line of "Usage".  "rt3" should of course be "rl2". This is what I get for trying to change (simplify) things after copy-pasting from my test TW5.  (I'm also trying to figure out how Google groups works... I see I can't make edits after posting...)

On Sunday, December 7, 2014 11:02:48 PM UTC-5, jess wrote:
Hi Stephan (and anyone else following along),

I made some minor modifications as follows, setting the system tiddler that holds the reveal-state within the macro rather than within the calling tiddler; the calling tiddler provides a unique "id" parameter for each link/reveal pair.

\define reveallink(id, link)
<$reveal type="nomatch" state="$:/temp/state-$id$" text="show">
 
<$button set="$:/temp/state-$id$" setTo="show" class="btn-invisible btn-link">
    $link$
 
</$button>
</
$reveal>
<$reveal type="match" state="$:/temp/state-$id$" text="show">
 
<$button set="$:/temp/state-$id$" setTo="hide" class="btn-invisible btn-link">
    $link$
 
</$button>
</
$reveal>
\end

\define revealtiddler(id, childtiddler)
<$reveal type="match" state="$:/temp/state-$id$" text="show">$childtiddler$</$reveal>
\end

Usage:

!Paragraph the second
This is a pararaph, with a <<reveallink "rl1" "link">> to another tiddler. More text comes after this. And still more here. Blah blah bladdy blah.

<<revealtiddler "rl1" "{{First child tiddler}}">>

<<revealtiddler "rl2" "{{Second child tiddler}}">>

Here is a second paragraph, and here is another <<reveallink "rt3" "reveal link">>. The child tiddler for this link will be revealed above this paragraph.

Out of curiosity, these "temp" tiddlers that hold the reveal-state, what is the best way to manage those? Should I be concerned if I end up with many of them showing in my sidebar (under System view)?

Thank you again,

-jess


Tobias Beer

unread,
Dec 8, 2014, 6:22:38 AM12/8/14
to tiddl...@googlegroups.com
Hi Jess,
 
<<reveallink "rl1" "link">>
 
Out of curiosity, these "temp" tiddlers that hold the reveal-state, what is the best way to manage those? Should I be concerned if I end up with 
many of them showing in my sidebar (under System view)?

Personally, I would not use rl1 because not only does it clutter your timeline but it is also persisted.

In case you actually want it to be neither visible nor persisted, I would recommend using $:/temp/rl1 and then prevent all $:/temp/foo from being saved using this method. I think I'm actually going to use $://foo for all temporary stuff, as it is the most concise way to type and hide things.

I have put this solution up on tb5, called the macros toggle and show, simplified state handling and enhanced with a link class:


Best wishes, Tobias.

Tobias Beer

unread,
Dec 8, 2014, 6:36:38 AM12/8/14
to tiddl...@googlegroups.com
What I would really like to know is, how can I prevent TiddlyWiki from becoming "dirty" when creating a state tiddler called...

$://foo

... yes, those two forward-slashes are intentional!

Best wishes, Tobias.

jess

unread,
Dec 8, 2014, 8:45:44 AM12/8/14
to tiddl...@googlegroups.com
Hi Tobias,

Thank you for the comments and enhancement to Stephan's solution. Yours is also one of the TW sites that has helped me greatly in the learning process, so thank you as well for that!

I am already using the $:/temp/state-$id$ syntax from an id (the "rl1") passed into the macro as a parameter. I am glad to know there is a solution for preventing these sort of state-tiddlers from being saved. Agreed though, the fact that the creation of these makes the TW "dirty" is a concern.

Is it possible to set a "cookie" from TW5 and use that to save state instead, and therefore prevent the "dirty-ing" of TW?

Thanks,

-jess

Tobias Beer

unread,
Dec 8, 2014, 11:37:54 AM12/8/14
to tiddl...@googlegroups.com
Hi Jess,
 
I am already using the $:/temp/state-$id$ syntax from an id (the "rl1") passed into the macro as a parameter.

Ah, totally overlooked that — neat trick! Adopted without much second thought and updated:


I am glad to know there is a solution for preventing these sort of state-tiddlers from being saved. 
Agreed though, the fact that the creation of these makes the TW "dirty" is a concern.

States under $:/temp/ or $:/state/ don't seem to do that.
So there's no concern the way you / we prefix states now.
 
Is it possible to set a "cookie" from TW5 and use that to save state instead, and therefore prevent the "dirty-ing" of TW?

Cookies don't provide the kind of persistence tiddlers do, so a decision was made against them. Which is ok, so long as there are ways of making things persist when we want them to or preventing them from doing so when we don't. Of course, if you prevented $:/temp/ and $:/state from ever being persisted, then your macro will never allow for reopening that toggle state next time you open that tw5. Right now, that's fine with me... and the way to change that is to simply change that state handling in that macro, if anyone ever wants to.

Best wishes, Tobias.

Jeremy Ruston

unread,
Dec 8, 2014, 4:16:58 PM12/8/14
to TiddlyWiki
> States under $:/temp/ or $:/state/ don't seem to do that.

There are two filters controlling saving TiddlyWiki as a standalone file.

* $:/config/SaverFilter determines which modified tiddlers trigger the dirty state

* $:/core/save/all determines which tiddlers are saved in the file

> Cookies don't provide the kind of persistence tiddlers do, so a decision was made against them. 

Just to be clear, the decision I made was to store all state in tiddlers. We don't yet persist tiddlers to local storage or cookies, but I do plan to support it - a big driver is so as to support individual independent usernames for tiddlyspot and tiddlyweb.

Best wishes

Jeremy.

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

Tobias Beer

unread,
Dec 8, 2014, 5:33:05 PM12/8/14
to tiddl...@googlegroups.com, jeremy...@gmail.com
> States under $:/temp/ or $:/state/ don't seem to do that.

There are two filters controlling saving TiddlyWiki as a standalone file.

* $:/config/SaverFilter determines which modified tiddlers trigger the dirty state
* $:/core/save/all determines which tiddlers are saved in the file

Thanks, very helpful to know about that.
I have have added [prefix[$://]] to the exclude filter
as it will give me a quick notation to define temporary, hidden things.

Best wishes, Tobias.

jess

unread,
Dec 8, 2014, 8:30:29 PM12/8/14
to tiddl...@googlegroups.com, jeremy...@gmail.com
Jeremy and Tobias, thank you both!
Reply all
Reply to author
Forward
0 new messages