Passing a tag to a template?

72 views
Skip to first unread message

Nathan Holden

unread,
Jun 9, 2017, 10:29:11 AM6/9/17
to TiddlyWiki
So I'm not sure if there's something I should have been trying to search here, but here's my concern.

I've got a static format I want to output, but I want to be able to maintain separate lists, and trying to use a template somewhere in there as well. I'm awfully new to this, so I'm sorry if this is super obvious.

So for an example, say we're throwing two parties, which we use as tags: JohnsBirthday, MomsBirthday

Then we have five tiddlers:

Title: Dad
Tags: JohnsBirthday, MomsBirthday, Guest
Name: Father

Title: Sarah
Tags: JohnsBirthday, MomsBirthday, Guest
Name: Sarah

Title: Karen
Tags: MomsBirthday, Guest
Name: Karen

Title: JohnsFriend
Tags: JohnsBirthday, Guest
Name: Redd

Title: New TV
Tags: MomsBirthday, GiftIdea
Name: n/a

Then we want to apply the template, for ALL cases of Guest...

Title: GuestListTemplate
Here's who will be coming to the party:

<$list filter="[tag[Guest]tag[x]">
<$view field="name"/>
</$list> 

Then, you would have two more tiddlers, which would include the full output of the template. So instead of code, I'm going to include the intended output

Title: Mom's Party
Body:

Gift Ideas:
 
New TV

Here's who will be coming to the party:
 
Father
Sarah
Karen

Title: John's Party
Body: 

Gift Ideas:

Here's who will be coming to the party:
Father
Sarah
Redd

Somehow, I want to be able to pass the tag JohnsParty or MomsParty to GuestListTemplate, so that I can avoid rewriting any more code than necessary.

Is this doable?

Mark S.

unread,
Jun 9, 2017, 2:03:00 PM6/9/17
to TiddlyWiki
You need some way to convey to the template whose party you want to report on. You could rewrite it as a global macro and then invoke it with <<guestlist "MomsBirthday">>.

Another approach is to set a field to select the celebration you want. For this example, I'm assuming you have:

title: Mom's Birthday
whose: MomsBirthday
text: {{||GuestListTemplate}} (with other text and templates)

then your GuestListTemplate would look like

 <$list filter="[tag[Guest]tag{!!whose}]">


    <$view field="name"/>
    </$list>

HTH
Mark

Nathan Holden

unread,
Jun 9, 2017, 7:26:35 PM6/9/17
to TiddlyWiki
Thanks! Worked like a charm!
Reply all
Reply to author
Forward
0 new messages