Template-Tiddler as Variable

Hello,

Is there a way to specify the template file “Template-a” centrally in a variable?
I have many calls in a Tiddler following this pattern:

{{Tiddler1||Template-a}}
{{Tiddler2||Template-a}}
{{Tiddler3||Template-a}}

Thank you very much.

You can create a custom procedure eg: _t for template

title: my-procedures
tags: $:/tags/Global
code-body: yes

\procedure _t(tiddler)
\whitespace trim
<$tiddler tiddler=<<tiddler>> > 
<$transclude $tiddler="Template-a" $mode="block"/>
</$tiddler>
\end

To call your procedures it would look like this

<<_t "Tiddler1">>
<<_t "Tiddler2">>
<<_t tiddler:"Tiddler3">>

Explanation

If you call {{Tiddler1||Template-a}} it is a shortcut for the following code, which is used in the custom procedure.

<$tiddler tiddler="Tiddler1">
<$transclude $tiddler="Tempplate-a" $mode="block"/>
</$tiddler>

The tiddler-widget defines some internal variables and the currentTiddler variable, that can be used by the Template-a

Hope that helps
Mario

Thank you for your prompt reply.

Unfortunately, when I try it out, the command
<<_t Tiddler1>>
only displays the template. The content of Tiddler1 is not displayed for some reason.

The short version {{||}} and the long version work. Perhaps it is a syntax problem?

Update:

Sorry, I’m a bit busy today.
I’ve followed up on everything again. Things are happening :=).

Thank you very much

1 Like

Perhaps in your use-case, the templated transclusions are interspersed with other content, which you left out for brevity’s sake.

But if the three were really listed sequentially like that, the simplest solution is:

<$list filter="Tiddler1 Tiddler2 Tiddler3">

{{||Template-a}}

</$list>

Addendum:

I have since figured out why it wasn’t working:
It was because the name of the tiddler contained a colon (:).

Thanks again, @pmario and @Springer, for your efforts.

Sorry. I usually cover parameters in double quotes, how it should be. So

<<_t "Tiddler with spaces">> and <<_t "tiddler:with:colons">> would work.

See: https://tiddlywiki.com/#Procedure%20Calls

Procedure calls allow named parameters which look like this: <<_t tiddler:"Tiddler1">> where the parameter name is defined with the procedure definition. If there is only one parameter, the name can be skipped.

Named parameters and the value are separated with a “:” colon. So if you use the parameter without quotes, the parser thinks it is a named parameter.

Named parameters make sense, if a procedure has several parameters and only some are needed for the call.

I did update my example in the first post, to make it clearer for users, that may read the post in the future.

Thank you for the addendum, I’ve learned something new again.

PS: I hope to see light at the end of the tunnel someday :slight_smile:

Have a nice day

2 Likes

I hope you always glimpse light that draws you forward in TiddlyWiki!

Please come and ask more here if you get stumped.

I must say, though, that I never entirely emerge from the “tunnel” experience, because once I’m up and running with some cool solution, something inspires me to try developing some new project that stretches my skills once again. :slight_smile:

2 Likes