I’m trying to implement ‘polymorphic’ macros, that is macros, that have the same name but behave differently depending on the tiddler they are defined in.
Suppose, you have two tiddlers, Tiddler1
containing book data and Tiddler2
containing a picture. Both the tiddlers have a macro called show
to show specific details of their content. Of course, the details shown for a book are different from those shown for a picture.
Now, you want to abstract away these details and just tell the tiddlers to show
their content. This can be done by using an additional level of indirection:
- define a field called
show
- put a macro in this field that invokes the local
show
macro:<<show>>
- transclude the
show
field of the tiddlers:{{Tiddler1!!show}}
,{{Tiddler1!!show}}
One use case for this technique is for instance a tab widget showing different content for each of its tabs.
Now two questions:
-
Using the indirection field, how could I pass parameters to the macros.
-
Is it possible to avoid this level of indirection and call a macro of a specific tiddler directly, i.e. using the common syntax of OOP languages
MyTiddler.myMacro
?