Search code examples
macroswidgettiddlywiki

How do I pass the output of a tiddlywiki widget as input to a macro?


I have a tiddlywiki [TW5] macro to determine the age of a person--usage would be:

<<getAge birthDate deathDate>>

Usage:

<<getAge "1898-10-04" "1947-12-09">>

I want to use this macro on a person tiddler--a tiddler that identifies an individual. I also have event tiddlers--such as a person's birth and another for a person's death. Person tiddlers are tagged as "person", birth tiddlers are tagged as "birth" and "event" and death tiddlers are tagged as "death" and "event".

All event tiddlers have a date field and people field--the latter field is a list of people tiddlers associated with the event.

In a person tiddler I display a date of birth with this widget:

<$list filter="[tag[event]tag[birth]contains:people{!!title}]">{{!!date}}</$list>

...and death date with this:

<$list filter="[tag[event]tag[death]contains:people{!!title}]">{{!!date}}</$list>

The question is, on a person tiddler, how can I get the birth and death dates and pass them to the getAge macro?


Solution

  • It might be too late but a possible answer would be something like this:

    <$set name="birthdate" filter="[tag[event]tag[birth]contains:people{!!title}get[date]]">
      <$set name="deathdate" filter="[tag[event]tag[death]contains:people{!!title}get[date]]">
        <$macrocall $name="getAge" birth=<<birthdate>> death=<<deathdate>>/>
      </$set>
    </$set>
    

    Here I stored the dates in two variables before using them as parameters in the macro call.

    Note that I used the macrocall widget because I'm not sure if this can be done by calling the macro in the regular way.