Is there a TranscludeTemplate like there is a ViewTemplate or EditTemplate?

Howdy!

Is there a way for a tiddler to “know” that it’s being transcluded in something else? So that it displays differently when transcluded vs. when it’s viewed vs. when it’s edited?

Like, there’s a ViewTemplate and an EditTemplate… so if I want to decorate how my tiddlers display by themselves when being viewed I can create a new tiddler, tag it $:/tags/ViewTemplate and code up some UI. Same for $:/tags/EditTemplate when it’s being edited.

Is there a way to do something similar for transclusions, across the board?

Here’s my use case: I have tiddlers tagged “Highlight” that are passages from books or websites that I like. For almost all of them I write them as big blockquoted sections:

<<<
Here is the text of the highlight. It can get pretty long in here.

And run to multiple lines.
<<< via [[The Tiddler of the Thing I Got It From]]

That way when I transclude them into other pieces of writing I know where they came from.

It’d be awfully swell if the TransclusionTemplate (I know that’s not a thing) could detect that I’m transcluding something tagged “Highlight” and format it differently. That way, the tiddler itself could just be this:

Here is the text of the highlight. It can get pretty long in here.

And run to multiple lines.

…and I can have fields like source that point back at the source of the highlight. Then, when it’s transcluded, it looks more like what I’m doing now.

I think I’m going to end up making a macro that does this for me that transcludes these things through a template to handle the formatting, but I wanted to make sure I wasn’t missing anything. Being able to write {{Here is an interesting highlight}} is handier than <<my-new-macro "Here is an interesting highlight">>, but if I’m going to end up macro’ing up then so be it.

Thanks!

Yes, you can and this is something I am quite proud of, but when ever I have mentioned it get very little indication it is meaningful to others.

  • Here I give you the technical know how, see how you go implementing your desired result with this information.
  • Ask more specific questions if you need more help.

Use this package code-tiddler-variable.json (1 KB) or

On tiddlywiki.com place the following tiddler “Test transclude” containing;

{{transclude-me}} not current

{{||transclude-me}} using current tiddler

{{named tiddler||transclude-me}} using namedtiddler

code-tiddler=<<code-tiddler>>

Now create the tiddler to be transcluded transclude-me

!!transclude-me

Details:<<transclusion>>


code-tiddler=<<code-tiddler>>

<$wikify name=code-tiddler text="""<<code-tiddler>>"""> 
<$list filter="[all[current]match<code-tiddler>]">
  ''Here in code tiddler''
</$list>
</$wikify>

<$wikify name=code-tiddler text="""<<code-tiddler>>""">
<$list filter="[<storyTiddler>match<code-tiddler>]">
  ''Here in code tiddler - viewing in story only''
</$list>
</$wikify>

To demonstrate this can be modularised, I created a global macro that returns the “code-tiddler” in which it is “invoked” and use it in this demo, but you could use its code directly in your code tiddler.

Create a tiddler tagged $:/tags/Macro containing;

\define pipe() |
\define code-tiddler() {{{ [<transclusion>split<pipe>nth[2]] }}}

Now look at “Test transclude” to see all the magic.

  • I have three types of transclusion here to show the different responses
    • The first transcludes without using the current tiddler
    • The second allowing it to use the current tiddler
    • The third uses a named tiddler, which currently does not exist
  • Notice how the result of each transclusion varies
  • Open transclude-me to see how somethings do not pass through the transclusion into “Test transclude”
    • Note how to use the code-tiddler variable in filter we need to wikify it
    • Of particular note is, the last “lists” content will only display if the code-tiddler is being viewed in the story and is not passed through, as when using {{transclude-me}}ie The first transcludes without using the current tiddler

I feel this solution may deserve a plugin with some related tools, and the code-tiddler moving into the core one day.

  • Perhaps this highlights the match operator does not evaluate a macro name first?
1 Like

The easiest and most performant way to do this is to use a “transclusion template”. You only need to create a tiddler named eg: quote with the following content

title: quote
 
<blockquote>

<$transclude />

<cite><$link><$view field=book> {{!!title}}</$view></$link></cite>
</blockquote>

If the tiddler is saved, it gives you a transclusion warning. That’s no problem.

Your “highlight” text tiddler may contain some text as follows. The title of the quote tiddler should be meaningful, you can remember it.

I used a field named: book that contains the real name of the book eg:

title: alice-first-paragraph
book: Alice in Wonderland

Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversations?'

Now the quote template can be used like this:

title: test tiddler

A quote 

{{alice-first-paragraph||quote}}

If the book-field is missing, the template shows the title of the tiddler, where it comes from. For easy navigation the “cite” title is a link

That’s basically it.

More info about the used widgets in your template can be found a the docs

have fun!

3 Likes

Most of the times there is no need to use the wikify-widget. It should be the very last resort, if there is no other possibility to solve the problem, because of performance reasons.

1 Like

I don’t like it either but no one discusses the work arounds.

I just worked out that the filter syntax that allows you to include macros works, effectively wikifying or converting code to its result.

In this code

<$wikify name=code-tiddler text="""<<code-tiddler>>""">
<$list filter="[<storyTiddler>match<code-tiddler>]">
  ''Here in code tiddler - viewing in story only''
</$list>
</$wikify>
  • The match operator fails if you do not first wikify it.

I thought I stumbled on a solution, but I have lost it now, Oh so fragile it is.

@pmario Why cant the match operator given a variable not evaluate it first, like when you give a filter a macro, it is evaluated first, including using its parameters?

Thanks you two! I think I’m going to end up going with {{highlight tiddler||quote}} for this particular problem, I think that solves the main use case I was thinking of.

But! @TW_Tones you’ve given me a lot to think about! I first saw your code late last night when I should’ve been in bed and it completely bounced off my brain, I’m going to keep studying it today, I think it’ll still be useful and I think it has some interesting techniques I can use elsewhere.

I’m completely fascinated with TW as a live programming environment! :grin:

2 Likes

@TW_Tones, this is good stuff!

I wonder whether it’s easy for you to open up a live demo on a tiddlyhost site or some such. There’s lots of steps in your instructions for producing these results, so it may be daunting for novice users. But having transclusions display so that they’re recognizable as such (especially with variations depending on what’s being transcluded) is the kind of thing that even novices often want to do, I think (despite your experience with not getting lots of positive feedback on this effort).

Meanwhile, I too would love to see a general solution, like what OP @drhayes calls a TranscludeTemplate, by the way. But there are complications: some transclusions are inline (inserting a calculated numerical sum in a paragraph of text, and wanting it to display without distraction); others are block transclusions; some transcluded tiddlers will introduce their own internal divs and spans that may work against whatever display protocol might seem to make sense in the abstract.

I recall someone had devised an alpha-diluted background transparency css solution for transcluded stuff (which nicely “stacked” so that double-transcluded portions got a more saturated background effect), but I’m not able to reconstruct right now where that was shared.

-Springer

1 Like

I am still not sure I understand this use of the term. To me “TranscludeTemplate” like “MakeCar”, Although I feel I more than adequately provided the technical answer to the OT I am not sure @drhayes will see that, to answer the OT in full requires addressing a number of non-specific issues (in my view).

I would love to “open up a live demo on a tiddlyhost site”, I will see what I can do, but time without income is costly to someone currently without an income.

  • I think I would prefer a more general TiddlyWiki blog

I would love it if you can find this info and share here.

You did answer this question:

I did answer this question, where the solutions is a different one.

I picked the term TranscludeTemplate to correspond to $:/core/ui/ViewTemplate or $:/core/ui/EditTemplate, literally a tiddler that is invoked by the system when one tiddler is transcluded in another.

And maybe this fictional $:/core/ui/TranscludeTemplate has a ListWidget in it kinda like this:

<$list filter="[all[shadows+tiddlers]tag[$:/tags/TranscludeTemplate]!has[draft.of]]" variable="listItem">
<$transclude tiddler=<<listItem>>/>
</$list>

That way I could customize transclusions just like I’ve customized my “view” and “edit” UIs.

My specific use case of quotes is best served by something like {{Here is the quote tiddler||quote}}, but there’s some interesting space around the general question.

Considering how often transclusion is used in Tiddlywiki I don’t know that I really want TW to have a $:/core/ui/TranscludeTemplate or that the implementation would actually look like that… but I think you’ve got the first steps I might need for a solution. You’ve handed me a great puzzle. :grin:

EDIT: Just to completely beat this into the ground, here’s a screenshot of how I’m using this: wizard.estate

Understood! Your communications and contributions are much appreciated, and more neatly packaged demos certainly do take time and attention.

Speaking of time without income, I did try to pursue that vague recollection via forum threads and web searching. No luck so far. What I recall is that there was a pale reddish coloration applied to transcluded blocks (resulting in deeper red for more deeply nested blocks), and I think there were rounded corners, too. I tinkered with it and ran up against some apparent limitation for my practical purposes, and moved on. Someone else had floated a solution where transcluded portions were highlighted only on hover, with a note about or link to their source… I don’t recall the various roles of templates, css, or core-level tinkering in these solutions.

Look, I am sure its “my bad”, for some reason I am having trouble following exactly what is is you are trying to do or want. Also the above link is unreadable, it will not zoom to a readable size. Pleas share code in discourse code blocks not images.

It would be nice if your requirement was stated free from what you think part of the solution is. What do you want to see or functional requirements without any code. I don’t think, I am big noting myself when I can say I am a “transclusion specialist” but I it is not at all easy to give you tips without giving you all my tips, taking forever to type, and hope you see the relevant ones.

  • I am confident I answered your question, but in a way you could not visualise.
  • I am glad @pmario could see so as to provide you a solution
  • If I understood more clearly I can share some great tricks

All these things you mention should be really simple, I have researched transclusions to a deep level, even testing their limitations. Do ask and I can share but please as I said before;

What do you want to see or functional requirements without any code?

I’m not sure if the translucency is a core part of the plugin or just a stylesheet added for demonstration purposes, but I think the Rider plugin might be what you were looking for. I think I vaguely recall the variant solution you mention as well, but I couldn’t find it quite as readily. Just in case you’re still interested, @TW_Tones.

Edit: The other similar plugin might be inc? It doesn’t natively include highlighting on hover, but I’m sure it would be simple to add.

1 Like

@etardiff Rider was, indeed, absolutely what I recall!

The inc (presumably for include?) is something I’ve also played with, though what I was recalling on this thread was something that displayed as ordinary seamless (inline or block) transclusion, but which revealed the status as transcluded (and from where) only on hover.

At any rate, reverse-engineering the Rider plugin should allow us to achieve many of the desired effects, if we design around it.

Still, I do wonder whether we could do something more like what the OP would like. At least on my vision, that means being able to tweak the css (and maybe even more than that) that gets applied to existing ordinary transclusions — probably limited at first to transclusions called from within a non-system-tiddler’s text field, and affecting only how those transclusions look within the story river in view mode.

The main conceptual problem is still (for me) the difference between inline and block formatting. I may initially like the idea that {{transclude-this}} in a text field would always display (in the story river) as if I had typed

<<<
{{transclude-this}}
<<< [[transclude-this]] ({{transclude-this!!author}})

… but that will go very badly for most inline transclusions, such as “My name is {{$:/status/UserName}}”

The same awkwardness affects the Rider plugin. But with a macro-based solution, we’re specific and intentional about where it’s invoked, and we could easily clone it for inline transclusions, to invoke when we want to see (even in view mode) that a segment of what’s rendered is being pulled from somewhere else.

-Springer

This is my first post in a new community, so I’m not sure what the norms are. I asked my question, got a couple of answers (great answers!), and marked my question solved. I explained my problem a couple of different ways and thought I’d thanked everyone for their answers. I’m not sure what else I should be doing; my apologies for not being clear.

This was answered in two different ways and I’m confident I understand the solutions enough to be useful to me. I’m good now.

{{transclude-this}}

Is literally short-hand for (i.e. gets expanded into the same widget-tree as):

<$tiddler tiddler="transclude-this">
    <$transclude tiddler=<<currentTiddler>> field="text"/>
</$tiddler>

Similarly, this

{{transclude-this||with-template}}

is the same code as

<$tiddler tiddler="transclude-this">
    <$transclude tiddler="with-template" field="text"/>
</$tiddler>

NOTE: That in this final case, inner <$transclude> (& all the text it inserts) uses the OUTER $tiddler’s value for <<currentTiddler>>.

:wink:

https://tiddlywiki.com/static/Transclusion%20with%20Templates.html

1 Like