How to get SetWidget to work with transclusion + template?

62 views
Skip to first unread message

The Islander

unread,
Jun 18, 2020, 11:12:12 PM6/18/20
to tiddl...@googlegroups.com
Hi everyone,

I can't seem to be able to figure out how to get this to work. Appreciate your help.



\define mymacro(index1:"{{!!title}}")
<$set name="myvar" tiddler="tiddler1" index=$index1$>
<$list filter="[$:/.somewhere/<myvar>]">{{||$:/.somewhere/templates/mytemplate}}</$list>
</$set>
\end




Can't seem to figure out what I'm doing wrong.

1. I need to get a value from a data tiddler (tiddler1) with an index equal to the title field of the invoking tiddler (named index1 = {{!!title}}).
2. The result of first step = myvar.
3. I need to take the result and get a tiddler named $:/.somewhere/<myvar>
4. I need to display the resulting tiddler using a template named $:/.somewhere/templates/mytemplate

The results don't seem to work.

Appreciate your help!

Thanks.


TW Tones

unread,
Jun 18, 2020, 11:30:50 PM6/18/20
to TiddlyWiki
Islander

I presume you are calling this macro with 

<<mymacro>> and some times
<
<mymacro "tiddlername">>

In your macro you can use $(currentTiddler)$ to access a value from where the macro was "called"
\define mymacro()
<$set name="myvar" tiddler="tiddler1" index="$(currentTiddler)$">

<$list filter="[$:/.somewhere/<myvar>]">{{||$:/.somewhere/templates/mytemplate}}</$list>
</$set>
\end

However is the tiddler title a legitimate index?

Also you could do this to default to the current tiddler unless tiddlername is provided
\define mymacro(tiddlername)
<$set name=index-name
value="$tiddlername$" emptyValue="$(currentTiddler)$">
<$set name="myvar" tiddler="tiddler1" index=<<index-name>> >
<$list filter="[$:/.somewhere/<myvar>]">{{||$:/.somewhere/templates/mytemplate}}</$list>
</$set></$set>
\end


However I will add that it can depend on how you call the macro. The most guaranteed way is with the macrocall widget, that allows you a wider range of parameter sources

<$macrocall $name=mymacro index1={{!!title}} />
<$macrocall $name=
mymacro tiddlername=<<avarwithtiddlername>>/>

Id did not have the setup to test the above.

Regards
Tony


On Friday, June 19, 2020 at 1:12:12 PM UTC+10, The Islander wrote:
Hi everyone,

I can't seem to be able to figure out how to get this to work. Appreciate your help.



\define mymacro(index1:"{{!!title}}")
<$set name="myvar" tiddler="tiddler1" index=$index1$>
<$list filter="[$:/.somewhere/<myvar>]">{{||$:/.somewhere/templates/mytemplate}}</$list>
</$set>

Mark S.

unread,
Jun 18, 2020, 11:51:46 PM6/18/20
to TiddlyWiki



You can't substitute the < > brackets in the middle of a string like that. You can only substitute them inside a filter expression where a square bracket would have occurred. But there is a trick to concatenating strings in filters using the "addprefix" and "addsuffix" operators. So your filter expression might look like this:

"[[$:/.somewhere/]addsuffix<myvar>]"

But there's a way you can skip "set" and "list" completely:

\define mymacro(index1)
<$tiddler tiddler={{{ [[tiddler1]getindex[$index1$]addprefix[$:/.somewhere/]] }}}>
{{||$:/.somewhere/templates/mytemplate}}
</$tiddler>
\end

Remember to end your macro definitions with \end, BTW.

The Islander

unread,
Jun 19, 2020, 1:07:26 AM6/19/20
to tiddl...@googlegroups.com
Hello,

How would I make the below solution work if my definition looked like this?

\define mymacro(index1:"{{!!title}}")


I can substitute a hardcoded string (the same as the title) for $index1$ from your suggestion, but if I specify index1 to be {{!!title}} it doesn't seem to work.

Thanks!


Edit:

Looks like I can combine both your solutions to get the following:

\define mymacro
<$list filter="[[tiddler1]getindex[$(currentTiddler)$]addprefix[$:/.somewhere/]]">{{||$:/.somewhere/templates/mytemplate}}</$list>
\end


TW Tones

unread,
Jun 19, 2020, 4:49:23 AM6/19/20
to TiddlyWiki
With respect don't use title as you do. It will not work. That is why I suggested using the $(current)$ as I do in my example. They are equivalent.I believe you can't put references and macros inside the define (parameters).

regards
Tony

The Islander

unread,
Jun 20, 2020, 11:12:13 AM6/20/20
to TiddlyWiki
Hi Tony, thanks to you and everyone else. Your explanations are very helpful!
Reply all
Reply to author
Forward
0 new messages