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.
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.
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:
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.
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!
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.