Transclude a tiddler that has a macro with currentTiddler

This should be a quickie for someone here.

I have a macro that will appear in most tiddlers, which we will call children:

\define notesource() <$view tiddler=<<currentTiddler>> field="chapter.article"/> (<$view tiddler=<<currentTiddler>> field="pagenumber"/>) <$link>*</$link>

But I will want to transclude those tiddlers in other tiddlers, let’s call them parents, with <$transclude field="text" mode="inline-block"/>

The problem is that when viewing the parent tiddler, the chapter.article and pagenumber parts of the macro no longer show the data from the child tiddler but from the parent tiddler.

What do I need to change so that I am seeing the chapter.article and pagenumber of the child even when viewing from the parent?

That is, what do I put instead of <<currentTiddler>> in the macro? I have tried numerous things: {{!!title}}, <<storyTiddler>>

I also tried deleting the macro from the child and then transcluding the child with a template of <$transclude field="text" mode="inline-block"/> <span class="thingray"><$view field="chapter.article"/>, <$view field="pagenumber"/></span>

The problem is that inline-block doesn’t appear correctly in the parent, and if I change it to block, the chapter and page number bits go onto the next line after the text. In most cases I will want them on the same line as the text.

As you can see I gave it a good try before bothering you all. Any help I can get is appreciated!

That transclude widget is in your parent tiddler?

And “New Tiddler” is a child tiddler?

The transclude widget transcludes whatever “currentTiddler” happens to be, and the “tiddler” parameter is the template tiddler to use to display whatever “currentTiddler” happens to be.

So your transclude widget in your parent tiddler is showing the parent tiddler but using “New Tiddler” as the template.

Me thinks.

Sorry, the widget in the parent is <$transclude field="text" mode=“inline-block”/>.

But yes, New Tiddler was one of the child tiddlers.

Try this parent tiddler to see what happens:

<$tiddler tiddler="New Tiddler">
<$transclude mode=“inline-block”/>
</$tiddler>

Thanks, you answered before I could correct myself. The actual widget did not have tiddler="New Tiddler"

1 Like

Doesn’t matter.

When using the transclude widget, be aware that the tiddler parameter specifies a template tiddler.

The tiddler that is actually transcluded is whatever <<currentTiddler>>
is at the moment of transclusion.

Also, the only documented modes for the transclude widget are “block” and “inline”

Well, suddenly what wasn’t working before is now working. Not sure what I did.

In the parent:

* {{New Tiddler 1||$:/.giffmex/transclusion/template}}
** {{New Tiddler||$:/.giffmex/transclusion/template}}

In the template:

<$transclude field="text" mode="block"/> (you are right, inline-block wasn’t working)

That’s my favourite way of saying “hey, this is the current tiddler” for the transclude widget.

I’m not 100% sure if do understand your construction. But here’s a try.

Some general info first

Usually if you use wikitext transclusion with templates you do this:

{{ChildTiddler||TemplateTiddler}}

which is the shortcut form of

<$tiddler tiddler="ChildTiddler">
<$transclude tiddler="TemplateTiddler"/>
</$tiddler>

So IMO your template will be eg: notesource-template … All the widgets use <<currentTiddler>> as their default tiddler value.

<$view field="chapter.article"/> (<$view field="pagenumber"/>) <$link>*</$link>

So I assume you have a list with your child tiddlers. With this constructions it’s important to use the transclude-widget with the “template”.

<$list filter="[tag[child-tag]]">
<$transclude tiddler="notesource-template" mode="block"/>
</$list>

See: Transclusion docs


If you need the CSS Class Variables described in the TiddlerWidget docs you need to cover the transclude-widget with a tiddler-widget.

<$list filter="[tag[child-tag]]">
<$tiddler><$transclude tiddler="notesource-template" mode="block"/></$tiddler>
</$list>

Some code that I did create for testing. Not sure if that’s how your configuration looks like.

transclude-template-list-experiment.json (753 Bytes)

have fun!
mario

Thanks Mario!

I guess you didn’t see that I figured it out and marked what happened as my solution. It is very close to what you did. Blessings!

I switch the forum editor to fullscreen mode when I do write a reply and play with code to make sure it actually works as described. It sometimes happens that the chat is going on and I don’t see it. …

Since the work is already done, I do post it. May be others find it useful in the future.
-m

3 Likes

This place is definitly the place to be to progress and learn our favorite tool.
I found your solution useful for one of my wiki. But there is to much space between links in the list generated like a blank line under each list element.

Capture d’écran 2023-06-26 à 09.07.37|468x500

How may I correct this ?!

Hi Thomas,
There is a little issue with TW HTML code generation. The creation of P elements is a bit excessive. You can modify the list a bit as follows. We add a DIV element with a class=“small-v-gap” for smaller vertical gap to the parent tiddler

<$list filter="[tag[child]]">
<div class="small-v-gap"><$transclude tiddler="notesource-template" mode="block"/></div>
</$list>

Add a new tiddler eg: myStyles and tag it: $:/tags/Stylesheet … You can adjust the margin-top and -bottom separately as needed. Or you can set it to margin: 0; which would change the class name to .no-v-gap

.small-v-gap p {
  margin-top: .1rem;
  margin-bottom: .1rem;
}

Here’s the JSON: transclude-template-list-experiment.json (973 Bytes)

have fun!
mario

3 Likes