Transclusion:macro or template

336 views
Skip to first unread message

Mohammad

unread,
Sep 29, 2019, 3:06:55 AM9/29/19
to TiddlyWiki
I want to transclude a tiddler or different part of tiddler! I normally use template

So, for example
I want to show the content of a tiddler say myTiddler I use template-code tiddler as below

{{myTiddler||$:/utility/template-code}}


I can also wrap the content of $:/utility/template-code in a macro like tp-code and have 
the same functionality as below

<<tp-code myTiddler>>


Pros and cons

- writing the long name template is tedious in daily work
- using smaller name like tpcode makes it appear everywhere
- using macro is simple and its tiddler is hidden but semantically template is better


What do you think? and what do you propose

--Mohammad


PMario

unread,
Sep 29, 2019, 4:12:40 AM9/29/19
to TiddlyWiki
Hi,

I think, it depends a little bit on your personal preferences. ... Less typing is definitely an advantage for the macro approach.

One more advantage is, that you can "globally" change the behavior of the macro. So you only need to change your transclusion calls in 1 place.

Macros have been designed to "abstract" complexity away, to make repetitive typing tasks simpler.

Widgets and templates are the basic building blocks in TW. They give you maximum control.

Macros are the next "higher" level blocks. They allow you to create your own functionality. In most cases they expose less parameters, which makes them easier to remember / use.

just some thoughts
mario

Mohammad

unread,
Sep 29, 2019, 5:37:55 AM9/29/19
to TiddlyWiki
Thanks Mario!

--Mohammad

TonyM

unread,
Sep 29, 2019, 7:27:36 AM9/29/19
to TiddlyWiki
I agree with Mario's approach but add such macros can be designed to use defaults like current tiddler but allow tiddlername to be provided. You can introduce config switches, modes and default filters yet also allow these to be overridden.

For example I have a macro called field and its parameter is fieldname. It will display fieldnames content. However if the wiki is set to edit mode or the tiddler is set to edit mode you can edit Fieldname. That is macros allow you to drive additional functionality from the same invocation and override using parameters. You can do this with transclusion but macros can also transclued in adfition. Multiple macros can be in one tiddler or multiple tiddlers. Transclusions must be in one tiddler by itself unless you transclued from fields.

Regards
Tony

Mark S.

unread,
Sep 29, 2019, 11:23:25 AM9/29/19
to TiddlyWiki
Why do you have to use a long name? $:/tpcode

Mohammad

unread,
Sep 29, 2019, 11:32:22 AM9/29/19
to TiddlyWiki
Sometimes it is part of a plugin! Sometimes it is hidden!
I know I can use simple name, but assume for some reason it is not possible!

Mohammad

unread,
Sep 29, 2019, 11:37:31 AM9/29/19
to tiddl...@googlegroups.com
Great idea!
Thanks Tony!

I like the currentTiddler as default parameter value, this simplifies things.

Mohammad

unread,
Jun 1, 2021, 9:45:41 AM6/1/21
to TiddlyWiki
Bringing up this again:  Transclusion: macro or template

  1. Can I say, I should use template when I am going to use many fields like {{!!title}} or I use currentTiddler in my template?
  2. I think I have also heard from Jeremy that template trasclusions are faster that macro call! Is this true?

Saq Imtiaz

unread,
Jun 1, 2021, 9:54:14 AM6/1/21
to TiddlyWiki
  • Keep in mind that transcluding separate tiddlers is more performant than heavy use of macros and the difference can be significant in some situations. The result of parsing each tiddler is cached and reused the next time if the tiddler has not changed. The same technique cannot be used for macros and they have to be re-parsed every time, as they are not global but local to the widget tree.
    •  NEW IN: 5.1.23 Parse trees are now cached for macros that do not perform any text substitution either via parameters or variables (i.e. $parameter$ or $(variable)$).
From https://tiddlywiki.com/#Performance

PMario

unread,
Jun 1, 2021, 10:01:13 AM6/1/21
to TiddlyWiki
On Tuesday, June 1, 2021 at 3:45:41 PM UTC+2 Mohammad wrote:
Bringing up this again:  Transclusion: macro or template
 
  1. Can I say, I should use template when I am going to use many fields like {{!!title}} or I use currentTiddler in my template?
Not as a general rule. ... You can also use the "currentTiddler" variable in a macro and call it within different tiddler. eg: test this:

title: test-macro
tags: $:/tags/Macro
\define test() <<currentTiddler>>

title: a
<<test>>

title: b
<<test>>

  1. I think I have also heard from Jeremy that template trasclusions are faster that macro call! Is this true?
Partially yes.
But ... Since TW 5.1.23 that is only true if your macro uses text substitution eg: \define a(txt) $txt$ or $(someVariable)$

Where this really matters is for macros, that call themself. ... aka "recursive macro calls" as used in the TOC or tree-macro

-mario

PMario

unread,
Jun 1, 2021, 10:09:39 AM6/1/21
to TiddlyWiki
On Tuesday, June 1, 2021 at 3:54:14 PM UTC+2 Saq Imtiaz wrote:

From https://tiddlywiki.com/#Performance

At the moment I'm working on a plugin, that should allow us to expose more info to the user when "performance instrumentation" measurements are enabled.

This will be a plugin, that developers can use to get a detailed timing overview about filters and some global timings ... The idea has been discussed at github.
There is no published code yet.

-mario

Mohammad Rahmani

unread,
Jun 1, 2021, 10:57:33 AM6/1/21
to tiddl...@googlegroups.com
Hi Saq,
Hi Mario,

Many thanks for very useful information! I got the point! Coming from other languages, especially the modular ones (structured programming world) you tend to use macro!

I am trying to shift to template transclusion! 



Best wishes
Mohammad


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/36906d30-6df1-40b9-ab8e-60554da177cfn%40googlegroups.com.

Mat

unread,
Jun 1, 2021, 11:53:56 AM6/1/21
to TiddlyWiki
Mohammad wrote:
Pros and cons

- writing the long name template is tedious in daily work
- using smaller name like tpcode makes it appear everywhere
 
Coincidentally(?) there is a proposal on gh targeting exactly this. Do chime in with ideas or give it a thumbs up.

The emerging idea there is to "extend the transclusion syntax" to allow for shortened template names in transclusions.

<:-)

 

Mohammad Rahmani

unread,
Jun 1, 2021, 2:44:18 PM6/1/21
to tiddl...@googlegroups.com
Thanks Mat! 
Sure I will have a look!



Best wishes
Mohammad


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

TW Tones

unread,
Jun 1, 2021, 7:29:01 PM6/1/21
to TiddlyWiki
Mohammad

Not withstanding others efforts and developer activities in tiddlywiki, I have spent some time looking at making use of templates and transclusion in new and interesting ways. In many cases I can replace the functionality of many macros with templates. 

Here is a simple example. Display tag pills for the tags on the current tiddler
{{||(tag-pills)}}
or another tiddler
{{Home||(tag-pills)}}
You can also use the long form $transclusion

Where the tiddler ' (tag-pills) ' contains the following
<$list filter="[all[current]tags[]]">{{||$:/core/ui/TagTemplate}}</$list>

Basically snipits of code/macros variables etc... are captured in a tiddler and included in other tiddlers by a simple transclusion. In effect making reusable code blocks. 

I use the (brackets) so they can be found in the standard search but they are easy to tell apart from other tiddlers.

Interestingly they offer a replacement for the aforementioned concatenation macros (which cant not yet be optimised more).

Later I expect to use Marios custom markup to simplify this further eg
' tag-pills 
would transclude (tag-pills) with he current tiddler {{||(tag-pills)}}
I would also list all the possible transclusion tiddlers in the side bar so you can drag and drop into the text of any tiddler, to allow rapid design.

Regards
Tones

TW Tones

unread,
Jun 1, 2021, 7:31:00 PM6/1/21
to TiddlyWiki
Post script,

it would be trivial to also exclude the tiddlers wrapped in braces (tiddlername) from the standard search after design. ie no need to use the $:/ prefix.

Tones
Reply all
Reply to author
Forward
0 new messages