Variable inside a filter

70 views
Skip to first unread message

Steven Schneider

unread,
Mar 29, 2017, 3:40:23 PM3/29/17
to TiddlyWiki
I'm trying to, well, here's the code:

A > I define a macro fpnl (eventually, first previous next last) that accepts a tiddler (usually, <<currentTiddler>> and a field that has a value
B > I am trying to generate a link to the first & last & next & previous tiddler that shares the value on the specified field with the currentTiddler
C > right now, I can not get the list filter to work with the field and value variables. Obviously, my mistake is in the filter line (between 3 & 4 below).  I've tried:

[field:$field$<fieldvalue>]
[field:$field$[<fieldvalue>]]
[field:$field$[<<fieldvalue>>]]

Any suggestions?


\define fpnl(tiddler field)
1 tiddler: <<currentTiddler>><br>
2 field: $field$<br>
<$set name="fieldname" value=$field$>
<$set name="fieldvalue" value="<$view field=$field$/>">
3 value of $field$: <<fieldvalue>><br>
<$list filter="[field:$field$[<fieldvalue>]]">
4 <<currentTiddler>><br>
</$list>
</$set></$set>
\end

<$macrocall $name="fpnl" tiddler=<<currentTiddler>> field="season"/>
``(with current tiddler having field season=winter)
``


Thanks,

//steve.


Mark S.

unread,
Mar 29, 2017, 5:09:01 PM3/29/17
to TiddlyWiki
There's at least 2 mistakes in your code. But it's easy to make mistakes in the quasi-documented world of TW macros, parameters, transclusions ...

This:

<$set name="fieldvalue" value="<$view field=$field$/>">

isn't doing what you think it's doing. It's not assigning the value of the view to fieldvalue. It's assigning a string that gets passed on as "<$view field=$field$/>" which in turn gets processed on #3 and LOOKS like it's doing what you want. But what you want is (or probably is):

<$set name="fieldvalue" value={{!!$field$}}>

In the filter operator, this:

<$list filter="[field:$field$[<fieldvalue>]]">

should be

<$list filter="[field:$field$<fieldvalue>]">

Notice that the angle brackets replace one set of square brackets.

Good luck!
Mark


Reply all
Reply to author
Forward
0 new messages