[TW5] How to use parametric transclusion? [Resolved]

430 views
Skip to first unread message

Hegart Dmishiv

unread,
Sep 13, 2015, 10:48:32 AM9/13/15
to tiddl...@googlegroups.com
I see that it is possible in TW Classic to pass parameters when calling a template. From my MediaWiki experience, this is what I understand to be a fairly standard templating technique. From what I've seen so far of TW, "template" seems to have a whole other meaning, so please bear with me.

What I'm trying to achieve, as the TWC example I linked to above shows, is creating a template, let's call it tiddler "A". This template tiddler contains mostly formatting information, such as defining a table, and the placement of parameters ($1..$9) within the specified format. Then we have tiddler "B", which invokes tiddler "A", passing actual data to the parameters. When tiddler 'B" is rendered, it displays the data using the formatting found in tiddler "A". That, to me, is the function of a wiki template. That is what I'm trying to achieve in TW5.

Does anyone know how to do this in TW5? I have tried following the examples from TWC, but it just doesn't seem to work for me.

EDIT: While I've been typing this, I have seen that there needs to be a "tiddler macro" to make the instruction work. I hadn't noticed that before. I assumed the command...

<<tiddler [[Template]] with: "param1" "param2" "paramX">>

...was a built-in part of the TW core. Does anyone know if this macro will work as-is in TW5? I'm running TW5.1.9 on my wiki. How do I use the macro? I assume I just copy the code to the top of Tiddler "B" in my example above, then follow it with the <<tiddler ...>> invocation. Is that right?

However, when I open the tiddler macro I can only see the instructions for how use it, not the macro code itself. Similar to the template documentation I'm used to seeing in MW. Where is the macro code? I see the instructions are tagged with [[Core Macros]] Macro, so maybe I'm wrong on this, and it is a core macro from TWC, one which isn't in TW5. I'm confuzzled!

Sorry for my n00bishness. I'll stop now before I get everyone confused.

PMario

unread,
Sep 13, 2015, 11:09:47 AM9/13/15
to TiddlyWiki
TW5 is not 100% compatible with TWc. It is a rewrite from scratch.
see: http://tiddlywiki.com/#Macros:Macros%20Transclusion
-m

Hegart Dmishiv

unread,
Sep 13, 2015, 11:24:08 AM9/13/15
to TiddlyWiki

Thanks for the reply, but, um, does that mean I'll have to learn how to write JavaScript in order to do simple transclusion with parameters in TW5.x? What do widgets have to do with any of it? Sorry, what seemed to be a standard and simple technique is ending up in the "too hard basket". Why would a core functionality in a previous version no longer be available in the update? If we have to learn to write JavaScript to use it, then is it really even a wiki still?

I don't mean to be harsh, but I'm really disappointed that I've spent so much time on this so far, only to find that the most basic of functionality that I'll need from it is not readily available to me. I can do wikitext. I can't do JavaScript.

Mark S.

unread,
Sep 13, 2015, 1:21:45 PM9/13/15
to TiddlyWiki
If anything, TW5, IMHO, seems to have been written to discourage you from writing Javascript.

It's a matter of adapting to a new paradigm. It probably isn't anything like the main-line Wikis, for better or worse.

In TWC, what everyone was always trying to do was to find some way to iterate and display information from tiddlers that matched some criteria. This typically depended on 3rd party plugins. In TW5 that capability is built-in, in the form of the <$list> Widget (Widgets are bits of code that perform operations inside tiddlers).

Inside a list, you might frequently transclude the contents of tiddlers that have been selected by the "filter" parameter of the <$list> widget. The output fields from those tiddlers might be modified by a template tiddler.

The template tiddler would not, typically, use parameters. Instead, it would use fields that exist inside each of the generated. In fact, I'm not sure you can directly pass parameters to a TW5 template tiddler.

Depending on your use case, what you may actually want is a macro. Macros take parameters similar to templates in TWC.

This description is a bit hasty, I know. The best thing to do is to go to TiddlyWiki.com and read up on <$list>, transclusion, and macros. Then figure out what it is you want to accomplish. If you can't figure out how to do what you want, then come back with a description of your use case, and there's sure to be someone who will tell you how to do that (or that it can't be done without some feature not available yet).

Good luck,
Mark

PMario

unread,
Sep 13, 2015, 1:27:16 PM9/13/15
to TiddlyWiki
On Sunday, September 13, 2015 at 5:24:08 PM UTC+2, Hegart Dmishiv wrote:
Thanks for the reply, but, um, does that mean I'll have to learn how to write JavaScript in order to do simple transclusion with parameters in TW5.x?

You don't need JavaScript. What makes you think so? Just because a tiddler contains "macros can also be written as JavaScript modules." doesn't mean a user needs to know JS. This sentence is similar to "TiddlyWiki is written in JavaScript, if you want to expand the core functionality, you can do so".

This are the first 2 paragraphs.


A macro is a named snippet of text. WikiText can use the name as a shorthand way of transcluding the snippet. Such transclusions are known as macro calls, and each call can supply a different set of parameters that get substituted for special placeholders within the snippet.

 

For the syntax, see Macros in WikiText.


This and the links basically contains the stuff you need.

 
What do widgets have to do with any of it?

Widgets are the basic low level building blocks for TW. You don't need them at the beginning. But they will be handy if you get more experience.
 
Sorry, what seemed to be a standard and simple technique is ending up in the "too hard basket". Why would a core functionality in a previous version no longer be available in the update?

It is. The syntax is different. If you read the wikitext tiddler and the examples, you may see the difference: http://tiddlywiki.com/#WikiText
or http://compare-tw2-tw5.tiddlyspace.com/ may help you out. I recorded the differences that are important for me, there. So this list may be incomplete for you.
 
If we have to learn to write JavaScript to use it, then is it really even a wiki still?

As I wrote you don't need JavaScript, to create macros.
 
-mario

PMario

unread,
Sep 13, 2015, 1:29:00 PM9/13/15
to TiddlyWiki
On Sunday, September 13, 2015 at 7:21:45 PM UTC+2, Mark S. wrote:
Inside a list, you might frequently transclude the contents of tiddlers that have been selected by the "filter" parameter of the <$list> widget. The output fields from those tiddlers might be modified by a template tiddler.

There is no need to use the list-widget. You can use the list links macro: http://tiddlywiki.com/#list-links%20Macro

-m

Eric Shulman

unread,
Sep 13, 2015, 3:26:24 PM9/13/15
to TiddlyWiki
On Sunday, September 13, 2015 at 8:24:08 AM UTC-7, Hegart Dmishiv wrote:
In TWClassic, the core <<tiddler>> macro was used to perform transclusion.  It was later extended to add support for "with: param param param".

In modern TW, transclusion is done with native syntax, e.g. {{NameOfTiddler}}.  This renders the content of the specified tiddler.  Any TextReferences (e.g., {{!!somefield}}) in the content are replaced with the corresponding field values from the tiddler.

TW's transclusion syntax also lets you specify a second tiddler name, like this: {{TiddlerA||TiddlerB}}.  This allows you to use TiddlerB as a "template" to render the values stored in TiddlerA.  If TiddlerA has *fields* named "foo" and "bar", with values of "mumble" and "frotz" respectively, and TiddlerB contains:
   This is from {{!!title}}
   The value of foo = {{!!foo}}
   The value of bar = {{!!bar}}
then the output of {{TiddlerA|TiddlerB}} would be:
   This is from TiddlerA
   The value of foo = mumble
   The value of bar = frotz

Note that if the {{TiddlerA|TiddlerB}} syntax is invoked directly from TiddlerA, you can omit the first tiddler name and just write {{||TiddlerB}} to transclude the content of TiddlerB with values from TiddlerA (i.e., the "current tiddler" is applied by default)

You can also use *variables* to "pass" named parameters for the transclusion, like this:
   <$vars foo="mumble" bar="frotz">
   {{||TiddlerB}}
   </$vars>
where TiddlerB contains something like:
   This is from {{!!title}}
   The value of foo = <<foo>>
   The value of bar = <<bar>>

Thus, in TWC you write:
   <<tiddler NameOfTiddler with: arg1 arg2 arg3 ...>>
while in modern TW you write:
   <$vars var1="arg1" var2="arg2" var3="arg3" ...>
   {{NameOfTiddler}}
   </$vars>

Note that the *names* of the variables are arbitrary... you can use any names you like, not just $1 through $9, and you can have as many variables as you need (not just 9 total).

If you really want to use the old TWC syntax, here a TW macro that (mostly) recreates the old syntax:

\define tiddler(title,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
<$set name="$1" value="$arg1$">
<$set name="$2" value="$arg2$">
<$set name="$3" value="$arg3$">
<$set name="$4" value="$arg4$">
<$set name="$5" value="$arg5$">
<$set name="$6" value="$arg6$">
<$set name="$7" value="$arg7$">
<$set name="$8" value="$arg8$">
<$set name="$9" value="$arg9$">
{{||$title$}}
</$set>
</
$set>
</$set>
</
$set>
</$set>
</
$set>
</$set>
</
$set>
</$set>
\end


Note the use of separate <$set> widgets rather than a single <$vars> widget.  This is because <$vars> does not permit variables to start with "$" and we are trying to be as close to the old TWClassic usage as possible.  One difference: to substitute param values into the "content tiddler", you have to write <<$1>> instead of just $1.

Hopefully, this should be enough for you to achieve your goals.  Let me know if you get stuck....

enjoy,
-e
Eric Shulman
ELS Design Studios
TiddlyTools - "Small Tools for Big Ideas!"
InsideTiddlyWiki: The Missing Manuals

YOUR DONATIONS ARE VERY IMPORTANT!
HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:

Hegart Dmishiv

unread,
Sep 13, 2015, 7:46:04 PM9/13/15
to TiddlyWiki
Thanks everyone for the replies. My apologies for my petulance last night, I just couldn't see any way that I'd be able to continue using TW if I had to learn JavaScript first, which I'm glad to see isn't going to be the case.


On Monday, September 14, 2015 at 7:26:24 AM UTC+12, Eric Shulman wrote:
Thus, in TWC you write:
   <<tiddler NameOfTiddler with: arg1 arg2 arg3 ...>>
while in modern TW you write:
   <$vars var1="arg1" var2="arg2" var3="arg3" ...>
   {{NameOfTiddler}}
   </$vars>

Thank you so much for this Eric, that is exactly what I wanted to know how to do! I was looking at the Data Dictionary tiddler types and the TranscludeWidget in TW5, but couldn't find anything approximating the simple, elegant solution you have provided here.

The maximum limit of nine numerical parameters was a bit of downer when I first saw it in TWC, and I was starting to formulate creative solutions to get around that limit, such as breaking my template into multiple smaller templates, passing nine arguments to each one. I'm glad I can now use infinite, named parameters under TW5. That really is a relief.

As for a use case, this is just for an infobox, which is commonly floated to the right of a wiki page, near the top of the article. With my TW5 wiki though, I'll probably place them horizontally across the full width of the tiddler, because the sidebar in TW leaves little room for float:right.

Eric's solution above makes invoking a template and passing parameters to it, from another tiddler, a breeze. Now I'm off to work out how to create those named parameters on the target template itself. Wish me luck! :-)

Hegart Dmishiv

unread,
Sep 14, 2015, 12:47:25 AM9/14/15
to TiddlyWiki
On Monday, September 14, 2015 at 7:26:24 AM UTC+12, Eric Shulman wrote:
Thus, in TWC you write:
   <<tiddler NameOfTiddler with: arg1 arg2 arg3 ...>>
while in modern TW you write:
   <$vars var1="arg1" var2="arg2" var3="arg3" ...>
   {{NameOfTiddler}}
   </$vars>

I've just tried doing this, and it doesn't seem to work for me still. I may have done something wrong. Could someone possibly have a look at my online (dev) wiki and tell me why it isn't working please?

As a practice, I have created a template tiddler to apply CSS formatting to a single variable {{!!cons-text}} which is then invoked from an example tiddler using Eric's example of the <$vars>..</$vars> block. For some reason my transclusion works fine, but the parameter isn't parsed.

Hegart Dmishiv

unread,
Sep 14, 2015, 12:52:40 AM9/14/15
to TiddlyWiki
Sorry, that link to my online (dev) wiki isn't working. I tried enabling the TW feature to add the tiddler and the story flow to the URL, but Google doesn't seem to like it when the wiki is hosted on Google Drive.  Let's try this one instead...

https://googledrive.com/host/0B7OVeQzNSpUGOFdLY2hIbWJNMHM

The template is at #$:/_Templates/cons

The example tiddler is at #Example console command

Eric Shulman

unread,
Sep 14, 2015, 2:31:18 AM9/14/15
to TiddlyWiki
On Sunday, September 13, 2015 at 9:47:25 PM UTC-7, Hegart Dmishiv wrote:
On Monday, September 14, 2015 at 7:26:24 AM UTC+12, Eric Shulman wrote:
Thus, in TWC you write:
   <<tiddler NameOfTiddler with: arg1 arg2 arg3 ...>>
while in modern TW you write:
   <$vars var1="arg1" var2="arg2" var3="arg3" ...>
   {{NameOfTiddler}}
   </$vars>

As a practice, I have created a template tiddler to apply CSS formatting to a single variable {{!!cons-text}} which is then invoked from an example tiddler using Eric's example of the <$vars>..</$vars> block. For some reason my transclusion works fine, but the parameter isn't parsed.

The {{...}} syntax is used to retrieve values from tiddler fields (e.g., {{!!fieldname}}).  However, in your implementation, "cons-text" is not a tiddler field, but simply a variable defined in the current scope.  For variables, use <<nameOfVariable>>, like this:
<span style="display: inline-block; border: 2px solid black; background-color: black; color: GhostWhite; font-family: FixedSys, Terminal, monospace; width:90%;">~$ <<cons-text>> </span>

-e

Hegart Dmishiv

unread,
Sep 14, 2015, 3:54:06 AM9/14/15
to TiddlyWiki
That was the answer Eric, thanks, it all works perfectly now. I've got such a lot to do now, creating all the templates I'll be using for my offline wiki.
Reply all
Reply to author
Forward
0 new messages