Here I am, Eric, and thanks for your help. I hope I'll be able to explain 
clearly.

Let's have a bunch of dictionary tiddlers to work with (note that the first 
one is used as tag for the others):

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 Rock

title: 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

And the macro used for strings concat (stolen from Tobias Beer Ad-Hoc 
macro, http://tobibeer.github.io/tb5/#Ad-Hoc%20Macro)

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

Now if I create a tiddler like the following, it works, displaying a grid 
with dict's indexes names as header and indexes value in the rows:

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>

Now I would like to create more tables without duplicating the code, so I 
make a macro from the previous one:

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

The only differences are:

   - define and end pragmas
   - the value for the beginning set widget ($t$ instead of Music)
   
Finally I can change my Music Table content with this one:


title: Music Table (code from TableMacro)

<<table "Music">>

But unluckly it renders in an empty grid, but table headers.


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)$}}">>

... with...


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




-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/2564e2f9-dea6-480f-8245-1d421b76afa4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to