Putting transclusion inside a transclusion?

Hi,
So, let me explain. I have a tiddler that use a transclusion from another one. It use it multiple time, either to display the content or to access/write fields-values. The fields are always the same, only the name of the transcluded tiddler change. (it is for an editable table created via the TiddlyTables plugins)

I need to duplicate this tiddler and change the target of the transclusion. Multiple times. Would it be possible to store the name of the tiddler to transclude from a field of the “host tiddler”, into the transclusion command ?
Or any other way to achieve a similar result ?

Hi @TankinatorFR !

It looks like you could define a new ViewTemplate.

This one would be the new ViewTemplate

The ViewTemplate can be applied to any selection of tiddlers, based on filters, <$list> widgets, cascades, …

You can read an introduction to this concept here.

Fred

1 Like

@tw-FRed
Thank you for your answer.
I think I understand your solution, but if I do, I fear it won’t apply to my case. But I already see how I might use it in some other situations, so even if I am right… Thank you very much, I didn’t know about ViewTemplates before.

If I understand it well, a ViewTemplate would take the content of my actual “main tiddler” and import into a tiddler that also contain my dynamic table, and could use local fields as values for what was contained in the original “Main Tiddler” ?

Maybe I should explain myself more clearly.

I need to use multiple editable tables from the TiddlyTable plugin in the same tiddler. Each table, is called at least two time, one time to transclude the table itself, one time to transclude the text-field that define its rows.

But each time a new “main tiddler” and its set of “table tiddlers” have to be created (by duplication), you have to go in edit mode and change the destination of each transclusion inside the “Main Tiddler” 's code.

What I am wondering is “could the name of the tiddler to transclude be stored in a text-field ?”.
So instead of editing all transclusions related to “tableA0” to point toward “TableA45”, I would store the name of the table-tiddler inside a field named “TableA”, and just edit this field’s value 1 time.

It is just one of these moment where you lose a day trying to prevent someone else from doing mistakes later on, while also saving him 1 minute of work… :smiley::sweat_smile:

1 Like

Ok, I don’t think I understand your global problem, so I’m going to focus on your request instead.

Let’s say you have a TableA0 tiddler, containing your table.

Create a new tiddler in your wiki, add a field “mytable” with vaue “TableA0”, and add this code to the text of the tiddler:

! Direct transclusion

{{TableA0}}
{{TableA0!!tbl-filter}}

---

! Indirect constant transclusion

<$tiddler tiddler="TableA0">
{{}}
{{!!tbl-filter}}
</$tiddler>

---

! Indirect field transclusion

<$tiddler tiddler={{!!mytable}}>
{{}}
{{!!tbl-filter}}
</$tiddler>

You should see the TableA0 table transcluded 3 times, with the underlying filter text below.

If I understand well, your current code looks like the “direct transclusion” example.

You can use the <$tiddler> widget to change the source of a transclusion, like in the “indirect constant transclusion” example.

You can also store the tiddler’s name in a field and use the field value for the <$tiddler> widget like in the “indirect field transclusion” example.

Is it what you wanted ?

Fred

2 Likes

@tw-FRed Yes, it seems to work exactely like I wanted.
This indirect transclusion is what I was trying to create.
I had done some experiment with the <$tiddler>…</$tiddler>, but now I see where I was failling.
Thank you ! :+1:

If we look at the title of this Topic

Putting transclusion inside a transclusion?

This works and is common, I put this “summary” here for others that may visit this Topic

  • If in one tiddler you transclude a tiddler and in that tiddler you transclude another it just works
    • Make sure you don’t transclude your self or one of the tiddlers “above” or you get an infinite loop.
  • People often use the transclude short cut {{transcludename}} or {{||transcludename}} (acts on current tiddler) or {{tiddlername||transcludename}} (acts on tiddlername as current tiddler)
  • However the <$transclude widget can be use as well. This is the long form, not the short form, and as in the “solution to this topic” you can use this with the tiddler widget to set the current tiddler (other methods are available). The following is the equivalent of {{tiddlername||transcludename}}
<$tiddler tiddler="tiddlername">
   <$transclude tiddler="transcludename"/>
</$tiddler>
  • The following is the equivalent of {{||transcludename}}
<$transclude tiddler="transcludename"/>
  • The following is the equivalent of {{transcludename}}
<$tiddler tiddler="transcludename">
   <$transclude tiddler="transcludename"/>
</$tiddler>

I hope this throws more light on the use of transclude

2 Likes