Reusing pieces of code in a view/ edit template

I use an edit template to provide useful editing structure when I edit tiddlers. The template consists of a filter-customization pairs for various types of tiddders.

I have come to realize that I use the same code snippets several times. For instance,

<$button> {{$:/core/images/close-button}} <$action-setfield published-on=""/></$button>

Is used multiple times.

Is there a way I can define such things once and use that definition everytime I need to use this?

I might have to use it $detail widget or in a table, etc.

Make a Macro or transclude the code

Macro in a tiddler tagged $:/tags/Macro
\define mymacro() <$button> {{$:/core/images/close-button}} <$action-setfield published-on=""/></$button>

Use with <<mymacro>> where ever you want or in a view template

Or put it in a tiddler eg maymacro
<$button> {{$:/core/images/close-button}} <$action-setfield published-on=""/></$button>

Use transclude it with {{||mymacro}} where ever you want or in a view template.

The “||” in the transclusion says transclude it as if it was in the current tiddler, sometimes this is important because the transclusion may need to reference the <<currentTiddler>>

Otherwise well crafted button tiddlers can be tagged to appear in the toolbar of each tiddler or conditionally.

To start making your own buttons explore tiddlywiki.com and/or look and clone at the existing core buttons [all[shadows]prefix[$:/core/ui/Buttons]] Thanks @stobot

@TW_Tones - think you have a small typo there with the extra [ . Also, if the intent is to take the string and plug it into AdvancedSearch you’ll need the shadows bit like [all[shadows]prefix[$:/core/ui/Buttons]]

1 Like