On Saturday, October 31, 2015 at 9:45:40 PM UTC-7, Matabele wrote:
>
> I tried this -- it doesn't work :-(
> I created a global macro:
> \define currentTitle()
> <$list filter="[<storyTiddler>get[draft.of]] 
> [<storyTiddler>!has[draft.of]]">
>
> </$list>
> \end
>
> The result of a simple macrocall is as expected in both view and edit 
> mode: 
> <<currentTitle>>
>
> However, when I try this, there is no output in either view or edit mode:
>
> <$list filter="[tag<currentTitle>]"/>
> <$list filter="[<currentTitle>tagging[]]"/>
> <$list filter="[<currentTitle>listed[tags]]"/>
>
> Anyone know why?
>

There is a widespread and common misperception about macros.  Specifically, 
because they have a parameter passing syntax, they *look* somewhat like the 
function syntax in other languages.  As a result, there is an expectation 
that they *work* like functions do, and can "compute and return" a 
resulting value. However.... macros don't actually do any computation other 
than simple *text substitution* to replace any instances of $paramname$ and 
$(variablename)$ within the macro content and then return that modified 
content for further handling.

What happens with that result depends on where it is used:

* If the macro result is returned directly into a wiki context (i.e. 
<<macroname ...>> is embedded directly in wikitext), then the macro's 
output will be parsed ("wikified") and any <$widgets> and/or <<macroname>> 
references are then processed in turn.
* If a macro result is used as a widget parameter (e.g., <$widget 
paramname=<<macroname>>...></$widget>) or as a reference within a filter 
(e.g., [tag<macroname>]), then the macro's output is *not* parsed, and is 
simply used as literal text by the widget or filter handler.

The confusion arises because of this different contextual handling for the 
macro results...

In your example, the output of the "currentTitle" macro, which has no 
parameters, is always, literally:
<$list filter="[<storyTiddler>get[draft.of]] [<storyTiddler>
!has[draft.of]]">

</$list>

In the first context, where you parse and render the output of 
<<currentTitle>>, the <$list> widget is invoked, and the expected output is 
shown.  However, in the second context, where you use 
[...<currentTitle>...] within a filter, the output of the macro is *not* 
parsed, so the filter is, literally:
<$list filter="[tag[<$list filter="[<storyTiddler>get[draft.of]] 
[<storyTiddler>!has[draft.of]]">

</$list>]]"/>

One possible work-around is to first use the <$set> widget with the 
filter="..." param to get the actual filter result (the desired tag name), 
and then use that variable within the subsequent list filter (to list 
tiddlers that are tagged with that name), like this:
<$set name="target" filter="[<storyTiddler>get[draft.of]] [<storyTiddler>
!has[draft.of]]">
<$list filter="[tag<target>]"/>
</$set>

I hope this explanation helps,

enjoy,
-e

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/7241e19f-3512-49bb-a96d-e8774a5ff0fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to