How to open linked tiddler inside tiddler

Hello everyone,

I have a lot of tiddlers that I created over time tagged “idea”, and I’d like to make it so that a random one could be displayed inside a tiddler (transcluded), and a new one from the list would replace it when i click “random idea” again. (it’s important that it happens inside the tiddler because I would want it in the sidebar while editing other tiddlers)

I found a random tiddler macro by Mohammad on the forum and it works great, it looks like this when I use it <<randomTiddler filter:"[tag[idea]]" label:“random idea”>>

But right now it opens up a random tiddler in the story river and on subsequent clicks it opens new random tiddlers while keeping the old ones open, like a regular link, which is cool, but not what I’d like right now.

Can anyone please help me do this?

you can try this modified version:

\define randomTiddler(filter, label)
<$let seed=<<now XXX>>
      minNum  = 1
      maxNum  = {{{ [subfilter<__filter__>count[]] }}}
      randNum = {{{ [<maxNum>subtract<minNum>multiply<seed>divide[999]add<minNum>round[]]  }}}
>
<$reveal type="nomatch" state="$:/state/randomtid" text="show">
<$button set="$:/state/randomtid" setTo="show">randow</$button>
<$transclude tiddler={{{ [subfilter<__filter__>nth<randNum>] :else[subfilter<__filter__>first[]] }}}/>
</$reveal>
<$reveal type="match" state="$:/state/randomtid" text="show">
<$button set="$:/state/randomtid" setTo="hide">random</$button>
<$transclude tiddler={{{ [subfilter<__filter__>nth<randNum>] :else[subfilter<__filter__>first[]] }}}/>
</$reveal>
</$let>
\end
3 Likes

Thank you buggyj!
It almost works! In fact, it works flawlessly on tiddlywiki.com, but in my wiki it keeps changing the transcluded tiddler on its own every second or so. It’s odd.

Are you using any TiddlyTools Time add-ons?

Specifically, the TiddlyTools/Time/Ticker, which updates $:/temp/time/ticker once per second (to record the current timestamp) and causes a global refresh event to occur.

Normally, this refresh event is not a problem, as it will not cause anything to re-render unless it depends upon either the value in $:/temp/time/ticker, or uses a variable whose value is dependent on the <<now>> macro with a format that includes seconds or milliseconds (such as seed=<<now XXX>>).

If this is the case in your TiddlyWiki, try using a constant value (i.e., seed=123) and see if the unwanted refresh stops.

If it does, then you can change your code so that the seed is only recalculated when you push the “random” button by storing the random seed value in $:/state/randomtid like this:

\define randomTiddler(filter, label)
<$let seed={{!!$:/state/randomtid}}
      minNum  = 1
      maxNum  = {{{ [subfilter<__filter__>count[]] }}}
      randNum = {{{ [<maxNum>subtract<minNum>multiply<seed>divide[999]add<minNum>round[]]  }}}
>
<$reveal type="nomatch" state="$:/state/randomtid" text="hide">
<$button set="$:/state/randomtid" setTo="hide">random</$button>
<$transclude tiddler={{{ [subfilter<__filter__>nth<randNum>] :else[subfilter<__filter__>first[]] }}}/>
</$reveal>
<$reveal type="match" state="$:/state/randomtid" text="hide">
<$button set="$:/state/randomtid" setTo=<<now XXX>>>random</$button>
<$transclude tiddler={{{ [subfilter<__filter__>nth<randNum>] :else[subfilter<__filter__>first[]] }}}/>
</$reveal>
</$let>
\end

-e

1 Like

A-ha! I do have TiddlyTools Time add-ons! I think I have all of them but I only use the calendar, I wonder if i can delete all the other components (since i’m not using those), I’ll try to delete them, thank you for pointing it out! (this refresh thing has caused another plugin to misbehave [although at the time i had no idea what was the problem, but it’s clear now!])
And also thanks for the calendar (and other tools you made!)

Edit:
I tried it, removed all components I’m not using and it’s not refreshing now. Though interestingly it still gets a new random one whenever i scroll and the focused tiddler changes

Anytime the tiddler store is updated, a global refresh event occurs.

Since you are tracking “the focused tiddler”, it also triggers a refresh, and since your randomTiddler() macro is still using seed=<<now XXX>>, it still causes a new random tiddler to be chosen.

You should consider using my suggested modification where the seed value is stored in $:/state/randomtid, and is only updated when you click the “random” button. It will still display a randomized tiddler, but it will only update when you press the button.

1 Like

I tried it (earlier, before deleting the ticker) and I couldn’t make it work, but I will try again because I have a strong suspicion I just did something wrong haha! Will let you know how it goes as soon as i get to it for a second try!
Thank you!

The code I posted has a syntax error…

Change this:

<$let seed={{!!$:/state/randomtid}}

to

<$let seed={{$:/state/randomtid}}

Also, to properly display the random tiddler content, you should add mode="block" to each of the $transclude widgets, like this:

<$transclude tiddler={{{ [subfilter<__filter__>nth<randNum>] :else[subfilter<__filter__>first[]] }}} mode="block"/>

Addendum… here’s my cleaned up and simplified version:

\define randomTiddler(filter, label)
<$let seed={{$:/state/randomtid}}
      minNum  = 1
      maxNum  = {{{ [subfilter<__filter__>count[]] }}}
      randNum = {{{ [<maxNum>subtract<minNum>multiply<seed>divide[999]add<minNum>round[]]  }}}
      tid = {{{ [subfilter<__filter__>nth<randNum>] :else[subfilter<__filter__>first[]] }}}
>
<$button set="$:/state/randomtid" setTo=<<now XXX>>>random</$button><<tid>>
<blockquote><$transclude tiddler=<<tid>> mode="block"/></blockquote>
</$let>
\end

<<randomTiddler "[tag[HelloThere]]" test>>

Note that I removed the “hide” logic, since it wasn’t actually hiding the randomized content. I also added a bit of enhanced display that shows the random tiddler’s title and outputs the tiddler content within a blockquote.

enjoy,
-e