Triple curly braces and templates - tip

131 views
Skip to first unread message

TonyM

unread,
Mar 15, 2020, 11:55:54 PM3/15/20
to TiddlyWiki
Folks,

I was looking through tiddlywiki to find how it does things because if you are left on a desert island or isolated with corona virus and no internet, tiddlywiki is in some ways its own documentation. I came across this in the tiddler $:/core/templates/exporters/TidFile which piqued my interest.

\define renderContent()
{{{ $(exportFilter)$ +[limit[1]] ||$:/core/templates/tid-tiddler}}}
\end
\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]
<<renderContent>>

Already I often use the triple curly braces to get a quick filter result

{{{ [all[]prefix[New Tiddler]] }}}

Observe how the triple curly braces not only evaluates a filter but then displays the result via a template?

This is "documented" here https://tiddlywiki.com/#Transclusion%20in%20WikiText but it is easy to miss.

{{{ [all[]prefix[New Tiddler]]||$:/core/ui/ListItemTemplate}}}

For example the above uses the existing list item template to render the list resulting from the filter, but it is no different to the default

$:/core/ui/ListItemTemplate
<div class="tc-menu-list-item">
<$link to={{!!title}}>
<$view field="title"/>
</$link>
</div>

You can see how this template is quite simple;;
And lets edit it to include the description

Tiddlername Description
<div class="tc-menu-list-item">
<$link to={{!!title}}>
<$view field="title"/>: {{!!description}}
</$link>
</div>

Now you can use
{{{ [all[]prefix[New Tiddler]]||Description}}}

To list everything in the filter and its description if it exists.

Or make the template DescriptionRow
<tr><td><$link/></td><td>{{!!description}}</td></tr>

And use
<table>
<tr><th>Name</th><th>Description</th></tr>
{{{ [all[]prefix[New Tiddler]] ||DescriptionRow}}}
</table>

The possibilities abound.
have fun

Regards
Tony

Mohammad

unread,
Mar 16, 2020, 4:07:44 AM3/16/20
to TiddlyWiki
Added to TW-Scripts

Very nice tip!

If you have a look at TW-Utility, I have developed custom transclusion and I use them in TW-Scripts alot

--Mohammad

Mat

unread,
Mar 16, 2020, 3:36:51 PM3/16/20
to TiddlyWiki
Yeah, I keep forgetting triple curly templates then re-discovering them every few years. Now I'm set until 2022. Thanks Tony!

<:-)

TonyM

unread,
Mar 16, 2020, 5:12:01 PM3/16/20
to TiddlyWiki
Mohammad,

Thanks for sharing that. I was experiencing some issues with transcluding code and ensuring plain text with new lines, I am sure the answer will be in your macro.

  • Can you tell me the best way to explore your macros on the utility site?
  • Have you a way to extract specific utilities?
Regards
Tony

Mohammad

unread,
Mar 17, 2020, 12:49:17 AM3/17/20
to TiddlyWiki
Hi Tony,

 See this shadow tiddler: $:/plugins/kookma/utility/macro/transclusion

--Mohammad

TonyM

unread,
Mar 17, 2020, 3:43:26 AM3/17/20
to TiddlyWiki
Mohammad,

Thanks so much. Your code looks beautiful

It's the use of the codeblock I had not understood, to achieve unwikified output.

By the way since you are a prolific published of macros perhaps you would be interested in this defacto standard I have developed.

I have attached a modified version of your tiddler $:/plugins/kookma/utility/macro/transclusion and provided a tiddler that shows how to list the result.
  • In each tiddler defining macros I create a matching field with the syntax for each macro
  • A Separate listing allows the macro, its syntax and its location to be identified
  • You can change the scope of the list to only show macros in a particular set of tiddlers, eg $:/plugins/kookma/utility
  • If we can adopt this defacto standard we could have a control panel or info tab that lists all macros in the current wiki with syntax, whoever wrote the macro.
  • It helps identify if you had two macros of the same name, or locate a macro to clone and make a variation
  • We could improve it to also look at shadow tiddlers.
Regards
Tony

ForMohammad.json

Mohammad

unread,
Mar 17, 2020, 6:34:27 AM3/17/20
to TiddlyWiki
Hi Tony,
 Many thanks. This is also great for documentation.

Best
Mohammad

Mohammad

unread,
Mar 17, 2020, 6:40:22 AM3/17/20
to TiddlyWiki
Tony,
 Have you tried the show-macro?

Example:


2. Then create a new tiddler with the below content

<<show-macro $:/plugins/kookma/utility/macro/transclusion>>

3. Save and see what it displays

The show macro actually extracts all macros from a tiddler! In the above example it lists and displays macros in semantic format from "$:/plugins/kookma/utility/macro/transclusion" tiddler
Try this for other tiddler or even use a $list to list all macros in a wiki or a plugin!

The only drawback is show-macro cannot distinguish correctly the single line macros.

Best
Mohammad
Reply all
Reply to author
Forward
0 new messages