Transclude contents of a variable through a template?

So to transclude a tiddler through a template we can do this:

<$tiddler tiddler="contentTiddler">
<$transclude $tiddler="templateTiddler"/>
</$tiddler>

or

{{contentTiddler||templateTiddler}}

but what if the content I want is stuff that’s been defined in a variable?

The following doesn’t work but it kinda shows what I’m trying to do:

<$let content="literal stuff I want trancluded through the templateTiddler">

{{<<content>>||templateTiddler}}

</$let>

Hello @hoopyfrood
maybe this link Grok Tiddlywiki can help - Chapter 4 Transclusion
Update
I think this works
transclusion.json (373 Bytes)

Looks like @etardiff beat me to it. Mines probably wrong anyhow :grinning:

If your content is anything more complex than a literal value, you need to switch to filtered transclusion. The docs include an example of a template used to transclude filter results (spaces added below for clarity):

{{{ [tag[mechanism]] || TemplateTitle }}}

You can do the same with a single variable by using the filter syntax for variables:

{{{ [<content>] || TemplateTitle }}}

This short form can be convenient, but there are also alternatives:

<$tiddler tiddler=<<content>>> <!-- assuming <<content>> is a single title -->
<$transclude $tiddler="TemplateTitle"/>
</$tiddler>

For multiple titles, we can also rewrite the first example as a $list:

<$list filter="[tag[mechanism]]" template="TemplateTitle" />

or (taking advantage of the fact that $list widgets set the <<currentTiddler>> value for each result, by default)

<$list filter="[tag[mechanism]]">
<$transclude $tiddler="TemplateTitle" />
</$list>

or even

<$list filter="[tag[mechanism]]">
{{||TemplateTitle}} <!-- transcluding <<currentTiddler>> when the content tiddler isn't specified -->
</$list>
1 Like

I tried those and it resulted in:
“Missing tiddler “literal value of the variable I wanted transcluded” – click to create”

I know there was a discussion about virtual tiddlers that I couldn’t really follow, is that something that could apply here? (using a not-real tiddler to hold a variable’s value that can be used in the $tiddler widget?)

So I can’t really put the variable on its own tiddler to get transcluded through the template like that, its contents are more complicated, so I guess I’m asking more like how to call a variable through a template without putting it as the sole text of a tiddler?

a little more specifically, what I’m trying to do is like:

<$let content={{{ [<filter run that gets a fragment from the text field of a tiddler>] }}} >

{{<<content>>||templateTiddler}}

</$let>

Are you using $:/core/ui/ViewTemplate/body/default as your transclusion template? If so, that’s what I would expect to see for any values that don’t correspond to extent tiddler titles.

I think the term “virtual tiddler” is most commonly used to refer to “missing” tiddlers opened in the story river (e.g. by following a link); this lets you use a custom ViewTemplate instead of (or in addition to) $:/core/ui/ViewTemplate/body/default to display information pertaining to that title even when the title isn’t a “real” tiddler with its own field content. You could theoretically do the same thing with a $list template or filtered transclusion template, but that template would have to be designed to show information from/about tiddlers that do exist. For instance, you can test this example on TW-com:

<$let myVar="TiddlyBlink">
<$list filter="DailyNotes [<myVar>] [tag[HelloThere]]">

!!! <$link />
Linked from
<<list-links "[<currentTiddler>backlinks[]]">>

---

</$list>
</$let>

Here you can see that the first two values in the list filter produce titles that don’t actually exist as real tiddlers — but they can still be used as input values for the template. If you moved everything between the $list widget tags into a separate tiddler MyTemplate, you could use it with any of the syntax options I mentioned above.

Does this help? If not, I’m happy to try to help you figure out a solution, but it would be easier if you could give us more specific details about your use-case and what you’d expect to see if your variable doesn’t correspond to a real tiddler title.

I just put this in the reply to Sunny but what I’m trying to do is kind of like:

the filter run is using split and trim operators to get a specific fragment of the text field, and I want that fragment of text to be rendered through what I have in a template tiddler

I can’t think of any reason why that wouldn’t work — unless your template tiddler includes field transclusions like {{!!my-field}}, which obviously won’t show up if the content “tiddler” doesn’t exist and/or doesn’t have that field.

oooh yes my template is trying to get text from the {{!!text}} field, which doesn’t exist in a variable… I think I’m going to need to change the template itself a bit. Thanks for pointing that out!

{{!!title}} or <<currentTiddler>> should be safe to use in any template — they refer to the current value, whether it’s a real tiddler or not.