Looking for a transclude trick (Challenge)

125 views
Skip to first unread message

TonyM

unread,
Dec 23, 2019, 7:01:11 PM12/23/19
to TiddlyWiki
Folks,

To cut a long story short I wanted to challenge the group to see if there is a way to extract a tiddler title from an intermediate transclude. attached and Illustrated below;

Why?
Because in a number of new methods I am developing this is a gap in what I can do to simplify the sophisticated (but simple) use of transclusions. Such a solution could make even smarter transclude methods available and reduce the code needed to achieve them, or the need for changes in the core to expand designer options when building wikis.

Here are three tiddlers you can create on Tiddlywiki.com (use JSON file if you want)

Display tiddler
<h2>Display Tiddler</h2>
Current Tiddler=<
<currentTiddler>><br>
Display Tiddler=<
<storyTiddler>>

;Simple Transclude (1)
{{||intermediate}}

;Transclude with tiddlername (2)
{{tiddlername||intermediate}}

intermediate tiddler
\define intermediate() intermediate
<h2>Intermediate Tiddler</h2>
Intermediate Tiddler=<<intermediate>><br>
Current Tiddler=<<currentTiddler>><br>
Display Tiddler=<<storyTiddler>>

{{||final}}

final tiddler
<h2>final tiddler</h2>

<h3>How can I find the tiddler name of the intermediate tiddler here?</h3>
Intermediate Tiddler=<<intermediate>><br>
Current Tiddler=<<currentTiddler>><br>
Display Tiddler=<<storyTiddler>>

One solution is to edit the intermediate tiddler as in the example and define a variable based on a literal 
\define intermediate() intermediate
as included in the above.

However
  • I am looking for a way to avoid editing the intermediate tiddler to provide its name as a literal
    • I would accept a programmatic way to store the intermediate name in intermediate but ideally I would like to avoid editing "intermediate" at all 
  • Is there a way to derive this intermediate tiddler title by other means in final?
  • What if there was a second intermediate tiddler?
Hacking
  • Perhaps there is a way to get/set the last tiddler "doing the transclude" in "final"  by altering the transclude mechanism?
  • What if we could somehow determine the full branch used to get to any level deep
    • eg (in final) display intermediate final
      or (in final) display $:/core/ui/Buttons/edit final
Thanks in advance
Regards
Tony
display-intermediate-final-code-example.json

springer

unread,
Dec 28, 2019, 7:12:32 PM12/28/19
to TiddlyWiki
Tony, I have a feeling your challenge may be related to my question about finding a way for transclusions to "behave" as I would hope them to when the tiddlers they're in get rendered as tabs, etc. Yes? I'll watch this post... Cheers.

TonyM

unread,
Dec 28, 2019, 8:17:08 PM12/28/19
to TiddlyWiki
Folks,

I found my own solution to this challenge using wikitext and macros rather than a javascript code change. Perhaps one of our backend developers could do better, but this works.

The method is to parse the `<<transclusion>> variable to obtain the first value not equal to `<<currentTiddler>>` this may not be true in in some circumstances.

In a tiddler tagged $:/tags/Macro
\define pipe() |
\define curlyr() }
\define curlyl() {
\define transcludedTiddler() {{{ [<transclusion>removeprefix<curlyl>removesuffix<curlyr>split<pipe>!match<currentTiddler>] }}}

Thus if a "transcluded" tiddler contains 
<<transcludedTiddler>>
it will return the tiddler in which the variable is specified, blank if viewing the tiddler directly.

This macro is included with display/intermediate/intermediate 2 and final tiddlers in the attached json

How would we use this?
  • This allows your code to obtain the name of the tiddler in which it (the code) resides even if that tiddler has being transcluded.
  • This code could access a field in the transcluded tiddler `<$view tiddler=<<transcludedTiddler>> field="fieldname-in-transcluded-tiddler"/>`
I am now working on a way to save in the "first transcluded tiddler" `<<transcludedTiddler>>` as callingTiddler such that any transclusion that occurs in "first transcluded tiddler" can access "from where it was transcluded" via the callingTiddler variable.

Regards
Tony
transcluded-tiddler.bundle.json

TonyM

unread,
Dec 28, 2019, 8:19:37 PM12/28/19
to TiddlyWiki
Springer,

Do detail your issue re tabs, because I think we may already have a solution for tabs, it uses a template to transclude tabs and there is a variable called currentTab available inside each tab.

Regards
Tony

springer

unread,
Dec 28, 2019, 9:34:45 PM12/28/19
to TiddlyWiki
Tony, thanks! I did just post about it earlier this evening, with a link to my site

I'll look into currentTab... It sounds like I should rewrite my templates, but I'm still just barely treading water with my upgrade process. I'm still very far from getting up to speed with TW5 widgets and macros, and have been cobbling together solutions found on others' pages, with minor patches...

TonyM

unread,
Dec 28, 2019, 10:54:55 PM12/28/19
to TiddlyWiki
Springer,

I may have mentioned I went through the same as you, making the big jump from TWC to TW5 in part you will need to unlearn things. Much more can be done in native TW5 than in TWC which demanded plugins a lot more. I can recommend downloading a full copy of tiddlywiki.com and making it your own to read and experiment. Perhaps tag the doco you understand and need to review. I built an earlier version which contains customisations and plugins you may want to study https://tiddlywiki.psat.com.au/learn/

Fee free to ask how here of course.

Tony

springer

unread,
Dec 29, 2019, 12:00:44 AM12/29/19
to TiddlyWiki
Wow, Tony, thanks so much! I've just poked around the learning edition a bit, and have enjoyed it so far. I hope your site will help get me ahead of the curve, though the big dive will probably wait for summer. For now I have to find the right balance between indulging my geek-impulse (to understand TW5 well) and responsibly learning just enough (for now) so that I can back to *using* (and developing bottom-line content for) the site that I'll be teaching out of in just a couple weeks. After years of teaching my big course out of TW Classic for about forever (since 2005 actually), it's hard to imagine any other way of organizing information for students. 

I'm still grieving the loss of something like Clint Checkett's Redirect macro, for reasons much like those mentioned by tobaisch a couple years ago (in a post to which you responded), and I'm perplexed that nothing like it seems possible with TW5. But in all other ways, TW5 is looking like such a runaway boost to everything I already loved about TW Classic!

Best,

-Springer

TonyM

unread,
Dec 29, 2019, 12:15:40 AM12/29/19
to TiddlyWiki
Springer,

Please describe "Clint Checkett's Redirect macro" because I have no idea what it does, so I can't give an indicator if there is a method to replace it. I am sure I know more than I used to with TW5.

Regards
Tony

springer

unread,
Dec 30, 2019, 12:22:47 PM12/30/19
to TiddlyWiki
Tony,

I'll start a new thread, since it's not about transclusion.

-Springer
Reply all
Reply to author
Forward
0 new messages