transclusion of a complex tiddler

97 views
Skip to first unread message

Jean-Pierre Rivière

unread,
Apr 7, 2020, 6:39:41 PM4/7/20
to TiddlyWiki
Hi!

I'm using tiddlywiki v5.1.21 to produce some rulsets. I'd like to have some special kind of tiddlers for tips and warning.

Basically, I was thingking of a simple transclusion like:

{{look at that tip}}

which doe the trick, but you cannot see it's a tip. So I thought doing that:

<aside>
{{look at that tip}}
</aside>

(with a few css in the bargain). BUT the tranclusion in that xase is incomplete: the transcluded tiddler has not any paragraph (code <p>...</p>) even though is was coded so as to to have several ones. Which means it is useless. Even a simple <div> has the same failure.

I've tried looking for transclusion in this group. I notably saw tw5 magick trick for "full-enhanced" http://tw5magick.tiddlyspot.com/#Another%20TOC%20example but then I got an error: 'Recursive transclusion error in transclude widget'. My code is below:

! <span title="Edit section"><$button message="tw-edit-tiddler" param={{!!title}} class="btn-invisible"><$view field="title"/></$button></span>
<$transclude/>

(a direct paste of the original, in a tiddler named "full-enhanced").

I also poke at https://groups.google.com/forum/#!topic/TiddlyWiki/rsoiC7DdnsE which has some nice TOC tricks but far above my level of understanding.


Mark S.

unread,
Apr 7, 2020, 7:05:35 PM4/7/20
to TiddlyWiki
Try transcluding like this:

<$transclude mode=block tiddler="look at that tip"/>

Joshua Fontany

unread,
Apr 8, 2020, 1:55:09 AM4/8/20
to tiddl...@googlegroups.com
IT actually sounds like we want something closer to a transcluded-template. So, we are going to use 1) a tiddler marked as a global macro and 2) a template tiddler, and 3) a CSS tiddler, 4) a "tip" tiddler.

This example mirrors the "documentation macros" from the TiddlyWiki website.

In any tiddler tagged `$:/tags/Macro`
```
\define !tip(tiddler)
<$tiddler tiddler="$tiddler$"><$transclude tiddler="$:/templates/importantTip"/></$tiddler>
\end
```

Then in `$:/templates/importantTip` we can have:
```
<div class="tip-block"><div class="tip-icon">{{$:/core/images/tip}}</div> <$view tiddler=<<currentTiddler>> field="text"/></div>

```
And then we have a tiddler tagged wit `$:/tags/Stylesheet`:
```
.tip-block { border-left: 2px solid #e1e1e8; margin-left: 3em; padding-left: 0.6em; position: relative; }
.tip-icon { position: absolute; left: -3em; top: 0.2em; }
.tip-icon .tc-image-tip { fill: #5778d8; }
```
Finally in `TiddlerWithTipText` the text field contains:
```
This is a very important tip!
```

Now that is all setup, we can- in any other tiddler we like - call it like this:
```
Content that sets up context for a user tip.

<<!tip "TiddlerWithTipText>>

```

I have attached a quick screenshot of this in action on TiddlyWiki.com. I hope this helps demonstrate how combining just a few basic tiddlywiki concepts can be very powerful.

Some thing to note. In the macro, the `$variable$` text substitution will only work within the macro, which is why it is not used in the transcluded template. Instead, we set the <$tiddler> widget in the macro, and then in the template we call the <<currentTiddler>> variable (set by the $tiddler macro). If we want to extend this to be more flexible, we could allow the <<!tip>> macro to take another parameter like so:

```
\define !tip(tiddler template:"$:/templates/importantTip")
<$tiddler tiddler="$tiddler$"><$transclude tiddler="$template$"/></$tiddler>
\end
```

Now we can call it with one parameter, and it will use the default template. If we call it with 2 parameters it will use the value of the 2nd a the  template tiddler to transclude.


Best,

Joshua Fontany

(Edit: caught a few typos)


ComplexTranscludeMacroDemo.png



On Tuesday, April 7, 2020 at 3:39:41 PM UTC-7, Jean-Pierre Rivière wrote:

Jean-Pierre Rivière

unread,
Apr 8, 2020, 6:53:27 PM4/8/20
to tiddl...@googlegroups.com
Than you Mark. This simple answer does the job, although I have to do many things manually. It's good enough for now.

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/pzdXfx9cMwQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/dd5ce6bb-16d7-425b-8772-8fbe3a54cd75%40googlegroups.com.


--
Jean-Pierre

Jean-Pierre Rivière

unread,
Apr 8, 2020, 7:17:16 PM4/8/20
to tiddl...@googlegroups.com
I cannot make functioning your elaborate mechanism, Joshua. I don't think I have made an error of ext. But well, no inclusion is done. No error is reported. Is there a way to debug this kind of scripting tw5? It would be helpful to know how to do it.

(sorry no screen capture, I've juste sen that it doesn't work yet).

Le mer. 8 avr. 2020 à 07:55, Joshua Fontany <joshua....@gmail.com> a écrit :
IT actually sounds like we want something closer to a transcluded-template. So, we are going to use 1) a tiddler marked as a global macro and 2) a template tiddler, and 3) a CSS tiddler, 4) a "tip" tiddler.

This example mirrors the "documentation macros" from the TiddlyWiki website.

In any tiddler tagged `$:/tags/Macro`
```
\define !tip(tiddler)
<$tiddler tiddler="$tiddler$"><$transclude tiddler="$:/templates/importantTip"/></$tiddler>
\end
```

Then in `$:/templates/importantTip` we can have:
```
<div class="tip-block"><div class="tip-icon">{{$:/core/images/tip}}</div> <$view tiddler=<<currentTiddler>> field="text"/></div>

```
And then we have a tiddler tagged wit `$:/tags/Stylesheet`:
```
.tip-block { border-left: 2px solid #e1e1e8; margin-left: 3em; padding-left: 0.6em; position: relative; }
.tip-icon { position: absolute; left: -3em; top: 0.2em; }
.tip-icon .tc-image-tip { fill: #5778d8; }
```
Finally in `TiddlerWithTipText` the text field contains:
```
This is a very important tip!
```

Now that is all setup, we can- in any other tiddler we like - call it like this:
```
Content that sets up context for a user tip.

<<!tip "tiddlerWithTipText>>

```

I have attached a quick screenshot of this in action on TiddlyWiki.com. I hope this helps demonstrate how combining just a few basic tiddlywiki concepts can be very powerful.

Some thing to note. In the macro, the `$variable$` text substitution will only work within the macro, which is why it is not used in the transcluded template. Instead, we set the <$tiddler> widget in the macro, and then in the template we call the <<currentTiddler>> variable (set by the $tiddler macro). If we want to extend this to be more flexible, we could allow the <<!tip>> macro to take another parameter like so:

```
\define !tip(tiddler, template:"$:/templates/importantTip")
<$tiddler tiddler="$tiddler$"><$transclude tiddler="$template$"/></$tiddler>
\end
```

Now we can call it with one parameter, and it will use the default template. If we call it with 2 parameters it will use the value of the 2nd a the  template tiddler to transclude.


Best,

Joshua Fontany

ComplexTranscludeMacroDemo.png



On Tuesday, April 7, 2020 at 3:39:41 PM UTC-7, Jean-Pierre Rivière wrote:
Hi!

I'm using tiddlywiki v5.1.21 to produce some rulsets. I'd like to have some special kind of tiddlers for tips and warning.

Basically, I was thingking of a simple transclusion like:

{{look at that tip}}

which doe the trick, but you cannot see it's a tip. So I thought doing that:

<aside>
{{look at that tip}}
</aside>

(with a few css in the bargain). BUT the tranclusion in that xase is incomplete: the transcluded tiddler has not any paragraph (code <p>...</p>) even though is was coded so as to to have several ones. Which means it is useless. Even a simple <div> has the same failure.

I've tried looking for transclusion in this group. I notably saw tw5 magick trick for "full-enhanced" http://tw5magick.tiddlyspot.com/#Another%20TOC%20example but then I got an error: 'Recursive transclusion error in transclude widget'. My code is below:

! <span title="Edit section"><$button message="tw-edit-tiddler" param={{!!title}} class="btn-invisible"><$view field="title"/></$button></span>
<$transclude/>

(a direct paste of the original, in a tiddler named "full-enhanced").

I also poke at https://groups.google.com/forum/#!topic/TiddlyWiki/rsoiC7DdnsE which has some nice TOC tricks but far above my level of understanding.


--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/pzdXfx9cMwQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.


--
Jean-Pierre

Jean-Pierre Rivière

unread,
Apr 8, 2020, 7:27:38 PM4/8/20
to tiddl...@googlegroups.com
However, in the same tiddler where I define !tip, I have defined !helloBuddy, which I have been able to use successfully. Here my code, complete with yours (this prove that the tiddler where it i written if functional, really):
--- BEGINNING ----
\define !tip(tiddler)
<$tiddler tiddler="$tiddler$"><$transclude tiddler="$:/templates/importantTip"/></$tiddler>
\end

\define !helloBuddy(someone)
This is nice to meet you, $someone$!
<$transclude mode=block tiddler="zorro"/>
\end
--- END ---
use of these functions:
<<!helloBuddy "Joe">>
<<!tip "zorro">>

Anyway, thanks so far for your help. Iv've already made a (little!) part of my journey into tw5 mastery!

--
Jean-Pierre
Reply all
Reply to author
Forward
0 new messages