mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-08-17 08:50:50 +00:00
![Jermolene](/assets/img/avatar_default.png)
@erwanm I ended up making some fairly extensive tweaks. One issue is that the (excellent) material you’ve provided on transclusion with templates covers very much the same ground as the existing TemplateTiddlers tiddler. The existing text was focused on transclusion with widgets; I think your material using transclusion notation is much easier to understand. I’ve also removed the exercises section. We don’t have exercises elsewhere in the documentation, so I think we need to make a conscious decision about whether we’re going to try to add them, and then do so consistently across the material. I also made some changes to bring the text into house style for consistency (which I’ve also tried to start documenting).
61 lines
2.5 KiB
Plaintext
61 lines
2.5 KiB
Plaintext
created: 20141129210304238
|
|
modified: 20141209142028738
|
|
tags: [[Transclusion in WikiText]]
|
|
title: Transclusion with Templates
|
|
caption: With Templates
|
|
|
|
! Introduction
|
|
|
|
In [[Transclusion Basic Usage]] 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.
|
|
|
|
The solution is to use a \\template\\. 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}}
|
|
|
|
See also:
|
|
|
|
* [[Transclusion in WikiText]]
|
|
* [[Transclusion Basic Usage]]
|
|
* TextReference
|
|
* TemplateTiddlers
|
|
* TranscludeWidget
|
|
* CurrentTiddler
|