Detect than a tiddler is transcluded

I have built a system where I constitute a whole article from parts, recursively. I use two templates for this, one for the nodes and one for the leaf.

Each part a a part number (“partnum” field). If the tiddler is transcluded within an an other part, I want to display tgat partnum. But not if it is not (that is, the tiddler is open in the main river story).

How can I check for that?

On looking for a solution, I saw there might be another approach with embedded story, but as I’m not interested by tweaking the parts, I shall keep my mechanism. But I could use the story mechanism to build the complete story. A kind of edit mode for the whole article, or part of it. Has anybody used it likewise? Would it be a god idea? Any hint about going that way?

1 Like

TiddlyWiki maintains a <<transclusion>> variable, which is based on different transclusion related elements.

Internally we did use this variable to detect recursion and it is also used to calculate a specific number using the <<qualify base:"x">> variable.

The qualify-macro is used to make the string shorter, but technically it is the “transclusion-variable-string” converted to a “number”.

This transclusion-variable and the qualify-string can be used to identify transclusions.


So as the first part you could test something as follows:

2 tiddlers named: aaa bbb where bbb transcludes aaa

title: aaa

<<qualify "x">> -- <<transclusion>>

and

title: bbb

{{aaa}}

It will look like this:

As you can see, there are 2 different variables and qualify output numbers.

Important:

If you edit a tiddler, those variables are different, to the view mode, since the preview is a template, which is transcluded in edit mode.

So you have to take care, which “numbers” are active in view-mode.


Suggestion

You should add this string <<qualify "x">> -- <<transclusion>> to both of your templates and see what happens.

Hope that helps
-mario

@pmario Tried it. First, a little problem: how to call qualify via transclude when nowhere in the doc is given the name of the argument of qualify. YATFRD (yet another time for revising documentation as new possibilities ask for more complete docs).

So I tried this:

* qualify via transclude: <<transclude variable=qualify tiddler=`$(currentTiddler)$`>> FOR <<currentTiddler>>
* qualify direct: <<qualify `$(currentTiddler)$`>> FOR <<currentTiddler>>
* transclusion: <<transclusion>>

which can render something like below:

This example is for a tiddler called “Documents normatifs” transcluded into a main story tiddler.

The same tiddler in the main story river:

  • qualify via transclude: FOR DAT::1.1 Documents normatifs
  • qualify direct: $(currentTiddler)$-907970045 FOR DAT::1.1 Documents normatifs
  • transclusion: {DAT::1.1 Documents normatifs|$:/user/gendat/templates/dat-leaf-part.template|||}

Should for this tiddler hard code something about the qualify result having exactly the number 907970045 in its value? I have a lot of parts, this seems clumsy. And could this number vary? Isn’t it a generic way to check for this?

Depending on how your templates are set up, you could compare the currentTiddler and storyTiddler variables. If they don’t match, then you’d have a case of transclusion.
This does depend on the currentTiddler specifying the current part correctly, though.

Yaisog

I did add a link to the qualify macro docs. There it says that the first parameter is a “title”.

There is a reason, why I did add a suggestion seen below. – If you choose to ignore it, that’s not a problem of the docs.

The parameter “x” is not important. The number generated is!

IMO there is no need to change my suggestion. Use it that way and run your tests – You’ll see what happens.

-m

Thank you @Yaisog’ this is exactly what I wanted, and in my case, it is working as required.

@pmario You’re right. I feel I should take vacations now. But I have to wait for a month!

hmmm,

I did add links to the macro tiddler and the examples tiddler to the link text (also in my OP)

qualify-macro is used to make the string shorter, but technically it is the “transclusion-variable-string” converted to a “number”.


I’m sorry if my comment was harsh but –

I think you give yourself a harder time as necessary, by using all the latest core features at once.

In general I think it’s a good thing to use the latests features! – But it also is a bit of a “mixed blessing”, if something does not work out as expected.

If that happens, it’s not really clear, if the new and “ambitious code” has a problem, or if using the “new feature” has a problem.

I do not have a general answer. I can only say, what works for me. I try to “keep it simple” and break it down into “smaller pieces”.

-mario

@pmario I think I’m going to let it loose on the \procedure stuff. This is along what you say. I can’t see any benefits of it for macro to be called on action gadget. They are nice for macros display. But as I also saw, this means that any rendering should be deferred to a template because being called by an action macro would mean no arguments for these.

You were not harsh, but true. I do appreciate being frank.

I will just add we can add to this the thisTiddler variable, and it inside a tab set the `currentTab variable.

  • A tiddler that is transuded will have a <<thisTiddler>> equal to the template or transcluded tiddler name/title.
  • I can no longer see a case where we have insufficient info for all related issues.
  • In the past I made use of the <<transclude>> variable but had to split it.

FYI: I am keen to also create an approach to the Qualify macro/widget which also includes the current $:/status/UserName

<% if [<thisTiddler>match<storyTiddler>] %>
This tiddler is not transcluded!
<% else %>
This tiddler is transcluded!
<% endif %>

:eyes:

1 Like

I am yet to explore the new conditional structure and how it works with the rest of tiddlywiki scripting but it is importiant to remember it is easy to use the same filter within standard filters like in the $list widget.