[TW5] Extracting things from a randomly selected tiddler

142 views
Skip to first unread message

David Sevilla

unread,
Jul 7, 2017, 8:07:30 PM7/7/17
to tiddl...@googlegroups.com
Hi,

I just installed tobibeer's random and setvars plugins in order to generate a random tiddler among those with a certain tag:

Random document: <$setvars _r="[tag[Document]!tag[Template]random[1]]" random="\{{{\ [r] \}}}\"
>
<<random>>
</$setvars>

So far, so good. But now I'd like to list the tags of that random tiddler, and that's where I am stuck  :)  I am basically trying to get a filter like [[<<random>>]tags[]] to work inside a widget (text, list...). My attempts:

1.
<$list filter="[[<<random>>]tags[]]" />

   should give me one "ok" per tag, but it prints nothing. I don't know why.

2. 
<$text text=<<random>> />

   gives me the tiddler name between {{{ }}} and, if not a simple name, also in [[ ]]. I don't know how I could cut that string so I can feed it to a filter (or combine strings to make one, see point 4).

3. Removing the triple braces in the definition of "random" does get rid of the text's curly braces of step 2, and if the tiddler name is simple enough there are no square brackets, but still the code of item 1 is not finding any tags.

4. At step 3, and with no-square-bracket names, I did <$list filter="[["+<<random>>+"]tags[]]"> ok </$list> obtaining a certain mess (I guess one cannot just add strings with "+", or I don't have such strings).

5. Just in case there was something weird between the initial angled bracket of the widget and the double ones of <<random>>, I substituted it with $macrocall. Nothing useful from that one.

Any suggestions are very welcome.

Mark S.

unread,
Jul 8, 2017, 4:52:10 PM7/8/17
to TiddlyWiki
Tobias <$setvar> and TW5 <$set> interpret filters differently, returning list items that internally have square brackets. My work-around was to strip them off with the removeprefix and removesuffix filter operators before looking for tags. Please excuse that I've changed the criteria to meet my available test data:

\define predb() [[
\define postdb() ]]
<$setvars _r="[tag[ToDo]!tag[Template]random[1]]" random="[r]">
<<random>> has tags --
<$list filter="[title<random>] [title<random>removeprefix<predb>removesuffix<postdb>]+[tags[]]" >
<$view field="title"/>
</$list>
</
$setvars>

This seems to work and take into account titles with spaces and titles without. Hopefully.

Good luck,
Mark

David Sevilla

unread,
Jul 9, 2017, 12:41:22 PM7/9/17
to TiddlyWiki
It worked like a charm! Thanks a lot.
Reply all
Reply to author
Forward
0 new messages