Transclude tiddler based on formatted headline

Hello forum,
I’ve a tiddler Lorem with this content:

I’d like to transclude in a new Tidder (Test) with a macro the content of Lorem with eg. h1 (all until h2).
I this case Lorem has more ‘sections’ with h1 → a pulldown of all h1 should be listed to choose.

Finally it should look like:

Any idea how to realize that?

Thanks, Stefan

1 Like

Hi Stefan

I have a feeling most replies here will be that you are going about it backwards.

It makes more sense, given how TiddlyWiki works, to put a paragraph like what you have contained in the green rectangle, in a separate tiddler, and transclude it here in the Lorem tiddler and also in Test and anywhere else where it needs to be transcluded.

There is no way to transclude only a portion of the text field of a tiddler, and so transcluding part of Lorem in a separate tiddler like Test can’t be done.

Think of most tiddlers as paragraphs or blocks, and some tiddlers as articles that combine those blocks in different ways through transclusion.

Have a look at @Mohammad’s section editor plugin, it allows you to edit sections within a single tiddler as delimited by the headings. It is one of the few examples of handling parts of a single tiddler differently to the whole tiddler.

  • This is not an answer to your question but may lead to one.

@StS I think there may be value in describing the activity you hope to make easy without reference to any code, because there may be more than one way to achive what your want.

1 Like

If you have a long written article in one tiddler, you won’t split it up to extra tiddlers to have the possibility to transclude it. There a some use cases for that.

It was just a question…

@DaveGifford, @TW_Tones thanks for feedback.

In Obsidian, it will transclude all things below h1, including text and h2 h3…

Link/Transclude to section will be unlocked after Feat: allow link to section mark by linonetwo · Pull Request #7744 · Jermolene/TiddlyWiki5 · GitHub

But it will works like in Obsidian.

If you don’t want h2 h3 below h1, you can transclude only a block of text under h1…Or we can think of a way to transclude thing between (and including) two anchors.

Hi Stefan, I hope you didn’t interpret my comment as criticism. I was just pointing out that your way of going about kind of goes against the grain of how TW works, so maybe reframing the idea might be a better approach.

You wrote: “If you have a long written article in one tiddler, you won’t split it up to extra tiddlers to have the possibility to transclude it. There a some use cases for that.”

My answer would be, Why wouldn’t you split it up? That is precisely what the excise button is for. To break up longer texts into their shorter components, especially if some of those components can be used in multiple places.

I think at times we all long for “splicing” of tiddlers, something that TW classic had. But since that is not possible in TW now, I think the best approach is looking at things backwards and letting the “splices” be external to the tiddler as separate little tiddlers.

One objection to using transclusion would be that when in the longer article tiddler it is not easy to open the transcluded tiddler. But there is a way around that: transclusion via templates. {{my tiddler||my template}}, where the template includes an unobtrusive link to the tiddler off in the corner.

Here is one I use that would work for your example. I think it was Eric who worked this up for me.

Create a tiddler entitled EditLink, and add the following as text. Then use {{||EditLink}} as your transclusion by template. It will put the tiddler title as a link, a button to edit the tiddler, and transclude the contents. If you don’t want the title as link, just change <$link/> to <$view field="title"/> and format as needed.

<$link/> <$button class="tc-btn-invisible"
   message="tm-edit-tiddler" param=<<currentTiddler>>
   tooltip={{{ [[edit "]addsuffix<currentTiddler>addsuffix["]] }}}>
  @@.donotprint {{$:/core/images/edit-button}}@@
</$button>
<$transclude mode="block"/>

The tiddler EditLink itself will look horrible, like a recursion. But the results work great. There is also CSS that can float the edit button all the way to the right, but I would have to do some digging to find it.

For the do not print CSS, you can add a stylesheet tiddler with the following:

@media print
{    
    .donotprint *
    {
        display: none !important;
    }
}

Anyway, even though it is not what you were originally asking for, I hope it is helpful. Blessings!

1 Like

Hey I found it. This json file contains

  • the EditLink I showed you above,
  • plus a second EditLink (EditLink 1), with only transclusion plus the edit button off to the right,
  • the CSS for float right,
  • and the CSS for do not print.

Download the json file, then drag it into your TW, and create a tiddler that transcludes another tiddler with {{||EditLink}} and {{||EditLink 1}} to compare the two ways of transcluding.

EditLink.json (1.3 KB)

1 Like

Hi @DaveGifford,
don’t worry, everything ok - when I ask the forum, I want collect some ideas / feedback.

EditLink.json is a nice tool - thanks.

I use subsume / subsume-edit- it does the same (collapsed).

Greetings
Stefan

1 Like

The TiddlyWikiClassic tiddler-macro has a functionality similar to what you describe. It is the “transclude section”: <<tiddler "test##heading-1">>.

It does transclude the text between “heading-1” and the next heading in the content. The content is transcluded without the heading.

In TW5 this functionality was not included anymore, for several (2014) reasons:

  • The main reason was bad performance
  • The transclusion link is very brittle
    • As soon as the heading changes, the link is broken without any warning
  • It’s against the Philosophy of Tiddlers.
    • As Dave mentioned: A tiddler should be the smallest reusable unit
    • Tiddlers should be used to compose longer stories

I think the main problem with the tiddler philosophy is, that we do not really have the right editor tooling, to make it convenient. Creating 1 tiddler per heading-section or even 1 tiddler per paragraph is a nightmare at the moment.

The streams-plugin is the closest UI that uses the tiddler philosophy. But not everyone wants to read their text as an outline.

Outlines are great for brainstorming – Taking fast notes in a meeting or while watching a video. But I think outlines always need several more refactoring steps.

For new users prose text with headings in 1 tiddler is easy to create, easy to be consumed and transferred as is.


TLDR; The current parse-tree contains a lot more info as the parse-tree from 2014. The parse-tree is cached. I think the possibility to transclude tiddler sections in a performant way should be reviewed again. May be as a plugin

3 Likes

Thanks @pmario for the explanation.

The TiddlyWikiClassic is unknown to me - long before I started :wink:

Another method for creating transcludable “named subsections” of a long tiddler (e.g, “Lorem”) is to wrap each subsection within a macro definition, and then invoke the macros to render the content, like this:

\define lorem_ipsum()
!!Lorem ipsum
blah blah blah
\end

\define aenean_blandit()
!!Aenean blandit
more blah blah blah
\end

<<lorem_ipsum>>
<<aenean_blandit>>

Then, you can invoke any of those macros in another tiddler (e.g. “test”) by importing the “Lorem” tiddler, like this:

\import Lorem
some content in test

<<lorem_ipsum>>
some more content in test

-e

2 Likes

Thanks Eric - I’ll give a try.

hihi,

Tiddler slices, tiddler sections and TagglyTagging from MPTW (Monkey Pirate TiddlyWiki) where the main features that initially drew me into Tiddlywiki.

1 Like

Given @DaveGifford’s idea, @EricShulman’s macro. @pmario’s reflection on gaps and some ideas I am exploring perhaps there is an approach.

Have a look at the macro function of the excise tool and Concider other macros.

The idea would be an editor toolbar button or more, that takes selected text or a named tiddler and creates a content macro and appends it elsewhere, but imports it here. This can handle alternative options like heading sections etc…

  • such macros can be globalized if needed
  • such macros could also leverage transclusions
  • transclude $variable is a new option
1 Like