$transclude $variable --> template?

I was expecting…

<$transclude $variable="..." $template="my-template" />

But $template is not a supported attribute of $transclude – so how?

Here is a construct I use fairly often: I want to replace line 5 with line 6.

1 <$let tiddler="$:/.rgt/bk/data/macro-doc-ui">
2   <h2><$text text=<<tiddler>>/></h2>
3   <div class="ad-hoc-fields-editor-div">
4     <$fieldmangler $tiddler=<<tiddler>>>
5       <!-- {{$:/.rgt/bk/data/macro-doc-ui||$:/core/ui/EditTemplate/fields}} -->
6       <$transclude $variable=<<tiddler>> $template="$:/core/ui/EditTemplate/fields"/>
7     </$fieldmangler>
8   </div>
9 </$let>
AFAICT, reading the docs...
  • “transclusion” articles talk about wikitext {{...}} and {{{...}}}

  • $transclude explains how to use the new and old mechanisms but doesn’t talk about shortcuts and doesn’t mention templates

  • “template” articles talk about “transclusion” but don’t mention $transclude

Am I missing something obvious?

{{ test || template }} is the short form of

<$tiddler tiddler="test">
<$transclude $tiddler="template" mode="block"/>
</$tiddler>

In the template you can then use <<currentTiddler>> because the tiddler-widget defines the currentTiddler variable.

The tiddler-widget also does define some other things, so you should use it that way

2 Likes

@CodaCoder – I think it would be nice, if you could post your new code, so we can see the difference to the code in the OP.

This is…

<$let tiddler="$:/.rgt/bk/data/macro-doc-ui">

<h2><$text text=<<tiddler>>/></h2>

<div class="ad-hoc-fields-editor-div">
 <$fieldmangler $tiddler=<<tiddler>>>
  <$tiddler tiddler=<<tiddler>>>
   <$transclude $tiddler="$:/core/ui/EditTemplate/fields" mode="block"/>
  </$tiddler>
 </$fieldmangler>
</div>
</$let>

completely unintuitive. Frankly, I’m amazed $transclude doesn’t offer $template.

$variable replaces template in the new form because you give the names of variables, procedures etc… It is equivalent to $macrocall.

You can still use macro call widget with procedures but some paramaters are not available.

I dont like it :nerd_face:

1 Like

Thanks guys, but really, there’s a gaping hole here.

Edited from the OP…

  • “transclusion” articles talk about wikitext {{...}} and {{{...}}}
      → and uses || to describe how to transclude through a template

  • $transclude (supposedly the real deal) explains how to use the new and old mechanisms but doesn’t talk about shortcuts and doesn’t mention templates

  • “template” articles talk about “transclusion” but don’t mention $transclude because they’re not supported

Perhaps because $macrocall never supported a $template attribute, it was (is) not “seen” as necessary?

I was thinking more about something as follows, which makes it possible, that the tiddler that contains the following code can easily be converted to a template too.

So it may be a bit unintuitive at first but in the long run it is much more flexible.

<$tiddler tiddler="$:/.rgt/bk/data/macro-doc-ui">

<h2><$text text=<<currentTiddler>>/></h2>

<div class="ad-hoc-fields-editor-div">
 <$fieldmangler>
   <$transclude $tiddler="$:/core/ui/EditTemplate/fields" mode="block"/>
 </$fieldmangler>
</div>

</$tiddler>

I agree there is a gap. It is both in the parameters naming and they documentation other wise it seems complete but its is prone to mislead.

  • apparently variables were always transcluded but this is the first time at became clear in an aspect of tiddlywiki script.
  • you transclude a variable OR tiddler/field into the current tiddler, which you can set.

There is also a gap or overly brief addressing of passing parameters with transcluded especialy in the short form.

  • I would add to the documentation but I am still developing my understanding.

Same here. Though I would say, if you were to devise a spec by reverse-engineering the docs, you’d end up with a mess. Fact is, the docs are written by those “suffering” from the curse of knowledge.

I’ll get there but I’m surprised to find I’m feeling like I’m “just starting out” on this topic.

@pmario I’m not saying there’s anything wrong with the pattern, as such. I’m surprised there is no $template attribute on the $transclude widget. That’s intuitive and much shorter.

I think if a transclusion-widget needs a template there is something wrong in the concept of the code. Templates are usually resolved using transclusions.

The tiddler-widget sets the “currentTiddler” variable to a tiddler title and defines some class-variables.

If you do not need the class variables, your code can be reduced to a template itself.

Like so:

title: my-ad-hoc-field-editor

\whitespace trim

<h2><$text text=<<currentTiddler>>/></h2>

<div class="ad-hoc-fields-editor-container">
 <$fieldmangler >
  <$transclude $tiddler="$:/core/ui/EditTemplate/fields"/>
  </$fieldmangler>
</div>

that can be called with:

\define currentTiddler() "$:/.rgt/bk/data/macro-doc-ui"

<$transclude $tiddler="my-ad-hoc-field-editor"/>

I think this construction is much more flexible in the long run. Your own templates can manipulate the currentTiddler variable, because it is only a convention every UI element can use.

As @pmario notes, the familiar {{currentTiddler||template}} syntax is a shortcut for a transclude widget targeting “template” nested inside a <$tiddler> widget that assigns the specified value to the currentTiddler variable.

So, the way to think about it is that the <$transclude> widget is entirely concerned with the template. There is no attribute called “template” because the other attributes $tiddler and $variable are two different types of template.

If we didn’t have the word “transclude”, it is entirely possible that we’d be calling it the <$template> widget.

1 Like

I’m slowly getting that and that exact thought ran through my head last night. Kind of explains some of the wrestling the docs need to go through, too.

If and when I truly get there, I may take a stab at improving them – though the style would be significantly different (part of the authoring trouble, I believe, is having to pay dues to the style currently in place).