Transclude global procedure, with parameters, from a button's actions

Continuing from my earlier journey, I’m now in need of transforming my procedure into a global one and calling it with passed parameters.

My current approach is the following global procedure which is called from person tiddlers where their title is the person’s name:

\procedure g-create-link-person-gift()
	<$action-createtiddler 
		$basetitle="GiftLink" 
		link-gift={{!!temp-gift}}
		link-person={{!!title}}
		tags=`link [[$(theTags)$]]`>
	</$action-createtiddler>

	<$action-deletefield 
		$field="temp-gift"/>

\end g-create-link-person-gift

which is called from a button inside a person as follows:

<$set name="theTags" value="todo">
	<$button
	disabled=<<giftSelectionEmpty>>
	actions=<<g-create-link-person-gift>> >
		To Gift
	</$button>
</$set>

It relies on “local” {{!!field}} references from person, and theTags which is also “locally” defined and is substituted to fill in the tags parameter.

I’d like to transition to something more reusable, with clearly defined parameters like (caution: the below are not correct):

\procedure g-create-link-person-gift(theLink, thePerson, theTags)
	<$action-createtiddler 
		$basetitle="GiftLink" 
		link-gift=<<theLink>>
		link-person=<<thePerson>>
		tags="link <<theTags>>" >
	</$action-createtiddler>

	<$action-deletefield 
		$field="temp-gift"/>

\end g-create-link-person-gift

and called with something like:

<$button
disabled=<<giftSelectionEmpty>>
actions=<<g-create-link-person-gift( {{!!title}}, {{!!temp-gift}}, "todo" )>> >
	To Gift
</$button>

I’m stumped on the required syntax to pass & call the 3 parameters. I’ve seen suggestions about using $transclude instead of <<macro>> for increased flexibility but I don’t understand how to apply that to $button's parameters.

incidentally are you placing global functions in a tiddler with the global tag, and rather than repeating code for each person put it in a tiddler with a view template tag?

  • wrapping your code in the view template with a list widget to only display on person tiddlers

These are arguably the best practice for such things.

I only ask because your words suggest you are not?

Yes on both fronts. I’ll have the aforementioned procedure in a Procedures tiddler tagged with $:/tags/Global and I’ll be applying it to all persons with a ViewTemplate. I’ll also be using it on all gifts for the same reason, but approaching it from the opposite direction.

The goal is to have the following:

  • On each person I want to select an available gift and create the appropriate link tiddler.
  • On each gift I want to select an available person and create the appropriate link tiddler.

Using {{!!title}} breaks the above approach; on half the cases it means “person’s name” and on the other half it means “gift’s name”.

Yes, we tend to write a lot of tiddlywiki script using the current title, and the list widget for example alters the variable <<currentTiddler>> but you can set a different variable name too eg variable=person. Another little trick if the currentTiddler has changed can be to revert to the <<storyTiddler>>