kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Merge pull request #1212 from erwanm/patch-4
doc: explanations about transclusion for beginners (directory concepts ok?)print-window-tiddler
commit
4c66eee1ec
|
@ -0,0 +1,92 @@
|
||||||
|
created: 20141129210304238
|
||||||
|
creator: Erwan
|
||||||
|
modified: 20141209142028738
|
||||||
|
modifier: Erwan
|
||||||
|
tags: Transclusion
|
||||||
|
title: TransclusionAsTemplateUsage
|
||||||
|
|
||||||
|
! Problem
|
||||||
|
|
||||||
|
|
||||||
|
In TransclusionBasicUsage we have seen how to include the content of a tiddler A into a tiddler B. Now suppose that tiddler A contains:
|
||||||
|
|
||||||
|
```
|
||||||
|
@@background-color:yellow;
|
||||||
|
Hello, my title is {{!!title}}
|
||||||
|
@@
|
||||||
|
```
|
||||||
|
|
||||||
|
This makes tiddler A display its title with a yellow background (see [[Styles and Classes in WikiText]] to learn about CSS style). Imagine that you want to display the title in the same way in tiddler B. But you don't want to copy/paste the style instructions, because you might want to change the background colour later and you want to keep it consistent among tiddlers. This looks like a typical case of transclusion, so let's try to transclude tiddler A in tiddler B the usual way with ``{{A}}``. You should see the following content in tiddler B:
|
||||||
|
|
||||||
|
<<<
|
||||||
|
@@background-color:yellow;
|
||||||
|
Hello, my title is A
|
||||||
|
@@
|
||||||
|
<<<
|
||||||
|
|
||||||
|
The style is applied as expected, but the title is wrong: we want ``{{!!title}}`` to refer to the target tiddler B, and not the source tiddler A.
|
||||||
|
|
||||||
|
! Solution
|
||||||
|
|
||||||
|
Thankfully TiddlyWiki provides a way to do exactly that, using ''templates''. In this case, the source tiddler A is called the [[TemplateTiddler|TemplateTiddlers]], and it is //applied// to tiddler B using the notation ``{{||A}}``. The difference is that any TextReference which does not refer explicitly to a specific tiddler is applied to the [[current tiddler|CurrentTiddler]], that is, the target tiddler. As a result, tiddler B now looks as expected:
|
||||||
|
|
||||||
|
<<<
|
||||||
|
@@background-color:yellow;
|
||||||
|
Hello, my title is B
|
||||||
|
@@
|
||||||
|
<<<
|
||||||
|
|
||||||
|
! Usage
|
||||||
|
|
||||||
|
Transcluding via a template is like applying a mask: assuming that the source tiddler contains generic references (like eye holes in a mask), these will be replaced with the target tiddlers values (like the eyes of the person who wears the mask).
|
||||||
|
|
||||||
|
A template can be applied to any tiddler, not necessarily the current one. This is achieved using the full notation ``{{<target>||<template>}}``. The default ``<target>`` is the [[current tiddler|CurrentTiddler]] (this is what we used in the above example).
|
||||||
|
|
||||||
|
! Examples
|
||||||
|
|
||||||
|
!! A predefined template to render tags nicely
|
||||||
|
|
||||||
|
You can apply the system template ``$:/core/ui/TagTemplate`` to a tag in order to see it as a tag pill with a drop-down menu:
|
||||||
|
|
||||||
|
```
|
||||||
|
{{Transclusion||$:/core/ui/TagTemplate}}
|
||||||
|
```
|
||||||
|
|
||||||
|
is rendered as {{Transclusion||$:/core/ui/TagTemplate}}
|
||||||
|
|
||||||
|
!! An exercise
|
||||||
|
|
||||||
|
Create three tiddlers A, B and C with the following content:
|
||||||
|
|
||||||
|
!!! in A:
|
||||||
|
|
||||||
|
```
|
||||||
|
Hello, my name is {{!!title}} and the last time I was modified is {{!!modified}}
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! in B:
|
||||||
|
|
||||||
|
```
|
||||||
|
{{||A}}
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! in C:
|
||||||
|
|
||||||
|
```
|
||||||
|
{{B}}
|
||||||
|
```
|
||||||
|
|
||||||
|
# Can you make C print //"Hello, my name is C ..."// without referring to A directly?
|
||||||
|
# Can you make C print //"Hello, my name is A ..."// without modifying C?
|
||||||
|
|
||||||
|
<$button set="$:/TransclusionAsTemplateUsageExerciseState1" setTo="show">Show the answers</$button>
|
||||||
|
|
||||||
|
<$reveal type="match" state="$:/TransclusionAsTemplateUsageExerciseState1" text="show">
|
||||||
|
|
||||||
|
# In tiddler C, replace ``{{B}}`` with ``{{||B}}``
|
||||||
|
# In tiddler B, replace ``{{||A}}`` with ``{{A}}``
|
||||||
|
|
||||||
|
<$button set="$:/TransclusionAsTemplateUsageExerciseState1" setTo="hide">Hide the answers</$button>
|
||||||
|
</$reveal>
|
||||||
|
|
||||||
|
See also [[Transclusion in WikiText]], TextReference, CurrentTiddler and TemplateTiddlers.
|
|
@ -0,0 +1,44 @@
|
||||||
|
created: 20141129201509859
|
||||||
|
creator: Erwan
|
||||||
|
modified: 20141130194810119
|
||||||
|
modifier: Erwan
|
||||||
|
tags: Transclusion
|
||||||
|
title: TransclusionBasicUsage
|
||||||
|
|
||||||
|
! Simple transclusion
|
||||||
|
|
||||||
|
To include some content from ~TiddlerA into ~TiddlerB, edit the latter and write:
|
||||||
|
|
||||||
|
```
|
||||||
|
This is the content of TiddlerA: {{TiddlerA}}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
As a result, the content of the field ``text`` (i.e. the main content) of ~TiddlerA is rendered in ~TiddlerB.
|
||||||
|
|
||||||
|
! Usage
|
||||||
|
|
||||||
|
|
||||||
|
The notation ``{{TiddlerA}}`` is actually a shortcut for ``{{TiddlerA!!text}}``. This is because by default the transcluded field is ``text``, but any other [[field|TiddlerFields]] can be used explicitly. For example, you can print the last time ~TiddlerA was modified using:
|
||||||
|
|
||||||
|
```
|
||||||
|
TiddlerA was modified on {{TiddlerA!!modified}}
|
||||||
|
```
|
||||||
|
|
||||||
|
The ``{{...!!...}}`` notation is also used to display the content of a field from the current tiddler, for example:
|
||||||
|
|
||||||
|
```
|
||||||
|
The current tiddler was modified on {{!!modified}}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is because displaying a field is also a form of transclusion. In this case, the notation ``{{!!modified}}`` used in ~TiddlerB is equivalent to ``{{TiddlerB!!modified}}``. In other words, the default value for the part before ``!!`` is the title of the current tiddler.
|
||||||
|
|
||||||
|
! Recursion errors
|
||||||
|
|
||||||
|
Notice that using ``{{!!text}}`` or ``{{}}`` causes an error (//Recursive transclusion error in transclude widget//), because it does not make sense to include the content of the current tiddler into the content of the current tiddler (that is, into itself). Whenever you encouter this error message, it means that you are trying to include something into itself, directly or not (for example if tiddler A transcludes tiddler B which transcludes tiddler C which, in turn, transcludes tiddler A).
|
||||||
|
|
||||||
|
! Going further
|
||||||
|
|
||||||
|
In TiddlyWiki, transclusions are not limited to including raw content like the above. To learn about a more advanced kind of transclusion, see TransclusionAsTemplateUsage.
|
||||||
|
|
||||||
|
See also: TransclusionAsTemplateUsage, [[Transclusion in WikiText]], TextReference, and TiddlerFields.
|
|
@ -0,0 +1,14 @@
|
||||||
|
created: 20141129194651420
|
||||||
|
creator: Erwan
|
||||||
|
modified: 20141130195444237
|
||||||
|
modifier: Erwan
|
||||||
|
tags: Transclusion
|
||||||
|
title: TransclusionPrinciple
|
||||||
|
|
||||||
|
A <a href="http://en.wikipedia.org/wiki/Transclusion">transclusion</a> consists in including some content from a tiddler A into another tiddler B //by reference//.
|
||||||
|
|
||||||
|
This means that, instead of having the same content in two different places (as what happens if the content is "copy-pasted" from A to B), there is a special instruction in B which indicates that this part should be taken from tiddler A. The first advantage is that if something is modified in A, the modification appears automatically in B as well. Thus it is easier to maintain inter-dependent content, since every piece of content is written in a single place, but can be viewed from many.
|
||||||
|
|
||||||
|
In TiddlyWiki the concept of transclusion plays a very important role because the [[Philosophy of Tiddlers]] is to connect small pieces of information together. But the concept is extended even further to allow for various kinds of useful features. To learn how to use it, see TransclusionBasicUsage and TransclusionAsTemplateUsage.
|
||||||
|
|
||||||
|
See also: TransclusionBasicUsage, TransclusionAsTemplateUsage, [[Transclusion in WikiText]], TextReference, TemplateTiddlers and TranscludeWidget.
|
Ładowanie…
Reference in New Issue