<$set name="t" value="myTiddler">
{{<<t>>}}
</$set>{{$(currentTiddler)$!!$(field)$}}
<$set name=v value=<<str """<$transclude tiddler=<$1$> field=<$2$> />""" """<r>""" """<i>""">> >
<<v>>
</$set>It works but I am looking for something better (simpler).
The (parametrized) transclusion I need stand within the body of two nested list widgets, that sets the tiddlers and the fields to be transluded, which in turns are concatenated using a wikitext macro. I pass variable to the macro using the syntax:and everything works fine.{{$(currentTiddler)$!!$(field)$}}
But when I try to move all of this code into a a macro tiddler (tagged $:/tags/Macro) the $(currentTiddler)$ value is empty. Forcing the list widget with a non default variable name does not solve.
I found that using <<currentTiddler>> instead of $(currentTiddler)$ works, but I cannot use this syntax within curly brackets.
title: Music
type: application/x-tiddler-dictionary
Album:
Artist:
Genre:title: Music 1
tags: Music
type: application/x-tiddler-dictionary
Album: Wish You Were Here
Artist: Pink Floyd
Genre: Progressive Rocktitle: Music 2
tags: Music
type: application/x-tiddler-dictionary
Album: Never Mind the Bollocks
Artist: Sex Pistols
Genre: Punk
title: Music 3
tags: Music
type: application/x-tiddler-dictionary
Album: Nevermind
Artist: Nirvana
Genre: Grunge
title: Music 4
tags: Music
type: application/x-tiddler-dictionary
Album: The Future
Artist: Leonard Cohen
Genre: Folk
title: StrMacro
tags: $:/tags/Macro
\define str(text,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20)
$text$
\end
title: Music Table (code within tiddler)
<$set name="t" value="Music" >
<table>
<!--------------
-- Table header
-->
<tr>
<$list filter="""[<t>indexes[]]""" variable="i">
<th>
<<i>>
</th>
</$list>
</tr>
<!------------
-- Table rows
-->
<$list filter="""[tag<t>sort[sort]]""">
<tr>
<$list filter="""[<t>indexes[]]""" variable="i">
<td>
<<str "{{$(currentTiddler)$##$(i)$}}">>
</td>
</$list>
</tr>
</$list>
<!--
-- Table rows end
------------------>
</table>
</$set>
title: TableMacro
tags: $:/tags/Macro
\define table(t)
<$set name="t" value="$t$" >
<table>
<!--------------
-- Table header
-->
<tr>
<$list filter="""[<t>indexes[]]""" variable="i">
<th>
<<i>>
</th>
</$list>
</tr>
<!------------
-- Table rows
-->
<$list filter="""[tag<t>sort[sort]]""">
<tr>
<$list filter="""[<t>indexes[]]""" variable="i">
<td>
<<str "{{$(currentTiddler)$##$(i)$}}">>
</td>
</$list>
</tr>
</$list>
<!--
-- Table rows end
------------------>
</table>
</$set>
\end
Finally I can change my Music Table content with this one:
title: Music Table (code from TableMacro)
<<table "Music">>
You said: "$(currentTiddler)$ only works within a macro"
I learned that I can use it in the macro invocation too
You said: "*Within* a macro definition, the value of $(currentTiddler)$ is always defined"
You're right, but it's not always defined the way I expect.
In this case I tried to remove the curly brackets, changing...
<<str "{{$(currentTiddler)$##$(i)$}}">>
<<str "$(currentTiddler)$##$(i)$">>
in my TableMacro. Now the grid is not empty anymore. Every single cell, but the headers, just as before, contains: "Music Table (code from TableMacro)##"
It is the title of the tiddler from which the macro is invoked and not the tiddlers that the list widget should return.
The real code is much more complex. I added stuff to sort columns, edit inline, select/unselect all or single rows, add fields, add records, change table and create a new one, everything using just vanilla TW5. I was excited for my results, but I'm only able to use all of this copying/pasting code from one tiddler to another.
I don't know what's wrong, but I'm sure there should be a better way. The code of my previous post was an attempt to find a workaround.
Here I am, Eric, and thanks for your help. I hope I'll be able to explain clearly.
<<str "{{$(currentTiddler)$##$(i)$}}">>
\define showIndexValue() {{$(currentTiddler)$##$(i)$}}<<str ...>><<showIndexValue>><$set name=v value=<<str """<$transclude tiddler=<$1$> index=<$2$> />""" """<r>""" """<i>""">> >
<<v>>
</$set>
{{<<r>>!!<<i>>}}<!-------------- Table rows--><$list filter="""[tag<t>sort[sort]]""" variable="r"><tr><$list filter="""[<t>indexes[]]""" variable="i"><$set name=v value=<<str """<$transclude tiddler=<$1$> index=<$2$> />""" """<r>""" """<i>""">> ><$set name=s value=<<str """<$transclude tiddler=<$1$> field=<$2$> />""" """<r>""" """<i>""">> ><td><!---------------------- View mode field--><$reveal state=<<s>> type="nomatch" text="edit"><$button class="tc-btn-invisible tc-tiddlylink" set=<<s>> setTo="edit"><<v>></$button></$reveal><!------------------- Edit mode field--><$reveal state=<<s>> type="match" text="edit"><$edit-text tiddler=<<r>> index=<<i>> tag="input" size=10/><$button class="tc-btn-invisible" set=<<s>> setTo="view"><small>{{$:/core/images/close-button}}</small></$button></$reveal></td></$set></$set></$list>