template: where is the widget???

116 views
Skip to first unread message

Jean-Pierre Rivière

unread,
Jun 28, 2021, 7:39:22 AM6/28/21
to TiddlyWiki
Hi!

I've read in the doc that widgets are the fundamental part of tiddlywiki and that all wiki syntax sugar is finally resolved as a number of widgets.

Use of template is only described with transclusion as {{||template}} (with tiddler or field or index before ||).

the transclude widget has no template attribute.

How then is done the transclusion? Shouldn't the transclude widget have a template attribute?

Also, I've come across $:/tags/ViewTemplate which is only described as: "The system tag $:/tags/ViewTemplate marks the view template." which is not very telling.

I've done tenplates tgat work fine. They are not tagged $:/tags/ViewTemplate. If I tag them as scuch, they act aout as if their content was twice included. What does $:/tags/ViewTemplate really do? How should it be used?

Regards,

-- 
Jean-Pierre





TW Tones

unread,
Jun 28, 2021, 9:41:54 AM6/28/21
to TiddlyWiki
Jean-Pierre,

The word template is over used in tiddlywiki, mostly because of the many ways to do templating. There are more possible than the common ones.
  • {{tiddlername}} is like incorporating content from a template containing text or code
  • {{||tiddlername}} says display tiddler name here, with the current tiddler as the underlying content ie; use the current text and fields title etc...
  • These are in fact just a short hand for transclusion see the <$transclued widget for the long hand form, the transclude say apply this tiddler here, ie use it as a template.
  • Tagging a tiddler with $:/tags/viewTemplate says please use this in the core template called  "viewTemplate" as you view each tiddler, the viewTemplate is a special template
  • Tagging a tiddler with $:/tags/editTemplate says please use this in the  template called  "editTemplate" as you edit each tiddler , the editTemplate is a special template
  • In fact in many ways macros are almost identical. When you use a macro its contents are pulled into the location where you use it.
  • Then after all your content development the finial result is transcluded, expanded, rendered, processed and displayed according to what you asked for.
In some ways it is best to return to the English definition of template;

template is a form, mold, or pattern used as a guide to making something. Here are some examples: A ruler is a template when used to draw a straight line. A document in which the standard opening and closing parts are already filled in is a template that you can copy and then fill in the variable parts.

In some ways, in code and tiddlywiki a template is simply a piece of reusable content. Almost everything is reusable in tiddler wiki, so almost everything can be used as a template.

Widgets on the other hand are very similar to html tags eg; <li>List item</li> or <br/> but the $ indicates you are referring to a <$widgetname/> and like html it can have attributes which are effectively the parameters to the widget. Widgets are the tiddlywiki way to introduce code such as html may use javascript. In fact most widgets are javascript but with one special feature, they honor the structure of tiddlywiki, they do what they do but in a way the whole wiki knows how to handle changes to itself, it is this magic ingredient that makes a wiki so interactive, always up to date and maintains the user interface. Widgets are a way to transclude functional code in your tiddlers.

I hope this clarifies things a little.

Topes

Soren Bjornstad

unread,
Jun 28, 2021, 10:18:20 AM6/28/21
to TiddlyWiki
I've read in the doc that widgets are the fundamental part of tiddlywiki and that all wiki syntax sugar is finally resolved as a number of widgets.

Use of template is only described with transclusion as {{||template}} (with tiddler or field or index before ||).

the transclude widget has no template attribute.

How then is done the transclusion? Shouldn't the transclude widget have a template attribute?

Actually, the template is what's being transcluded during a transclusion, not the tiddler. When you transclude a tiddler through a template, the current tiddler is set to that tiddler and then the template is transcluded.

{{Tiddler||Template}} evaluates to:

<$tiddler tiddler=Tiddler>
  <$transclude tiddler=Template/>
</$tiddler>

{{||Template}} doesn't change the current tiddler and so evaluates to simply:

<$transclude tiddler=Template/>

{{Tiddler1}} is shorthand for {{Tiddler1||Tiddler1}}, and evaluates to:

<$tiddler tiddler=Tiddler1>
  <$transclude tiddler=Tiddler1/>
</$tiddler>

More on templates and current tiddlers from my TiddlyWiki textbook.
 
Also, I've come across $:/tags/ViewTemplate which is only described as: "The system tag $:/tags/ViewTemplate marks the view template." which is not very telling.
I've done tenplates tgat work fine. They are not tagged $:/tags/ViewTemplate. If I tag them as scuch, they act aout as if their content was twice included. What does $:/tags/ViewTemplate really do? How should it be used?

Haha, some of those tag explanations could use some work. TiddlyWiki just transcludes all the tiddlers with that tag in sequence when it is rendering each tiddler:

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

So the view template is essentially a list of templates that get automatically transcluded for every tiddler without mentioning them in your wikitext. This includes things like the title, the tags bar, and so on.

Jean-Pierre Rivière

unread,
Jun 28, 2021, 7:15:35 PM6/28/21
to TiddlyWiki
Thank you to both of you for your explanation. The information on the system tag was very helpful.

@Soren: you write tgis in your textbook:

Here are some things that change the current tiddler:

  • Transcluding another tiddler with the {{curly braces}} syntax.
  • Using a $list widget to enumerate the outputs of a filter.
  • Directly setting currentTiddler with a $set or $vars widget.
Does it mean that you can change the content of a var or that you stack up vars, getting only the values from the top var?

Could it be used to have some kind of recursion in a safe way? I was thinking of vars as immutable stuff because of the syntax that declare them but no syntax to alter them otherwise.

And finnally, in a number of my templates, the template content is only <<myMacro>>. It seems a bit out of touch with what your telling me with what template are. In effect, myMacro is only used there. Would it b a better idea to ditch the macro and have the macro body directly into the template text? (yes, myMacro has no params.)

regards,

-- 
Jean-Pierre

PMario

unread,
Jun 28, 2021, 8:16:05 PM6/28/21
to TiddlyWiki
On Tuesday, June 29, 2021 at 1:15:35 AM UTC+2 jn.pierr...@gmail.com wrote:

Here are some things that change the current tiddler:
  • Transcluding another tiddler with the {{curly braces}} syntax.
  • Using a $list widget to enumerate the outputs of a filter.
  • Directly setting currentTiddler with a $set or $vars widget.
Does it mean that you can change the content of a var or that you stack up vars, getting only the values from the top var?

You "stack up vars". So variables have a scope. That's the reason why we sometimse need a construction like this:

title: myTemplate

\define concat() $(currentTiddler)$-$(title)$

<$list filter="a b c" variable=title>
<<concat>>
</$list>


Since the list-widget would "overwrite" the currentTiddler with the default setting we can provide a new variable name. In this case "title"
The currentTiddler is the tiddler, the code lives in.

If you create a new tiddler named: test ... You can play with templates.

title: test

{{myTemplate}}

---

{{||myTemplate}}

 
Could it be used to have some kind of recursion in a safe way?

Yes. We use recursion a lot. eg: the toc-macros.
 
I was thinking of vars as immutable stuff because of the syntax that declare them but no syntax to alter them otherwise.

As I wrote. Variables have a scope. They are valid inside the widget they are defined in .

\define test() abc
\define test() xyz

<<test>>  ... Will be xyz

So the last one wins. The above code is a "shortcut of"

<$set name=test value=abc>
<$set name=test value=xyz>

<<test>>

</$set>
</$set>

Try this:

<$set name=test value=abc>

<<test>>

<$set name=test value=xyz>

<<test>>

</$set>
</$set>

 
And finnally, in a number of my templates, the template content is only <<myMacro>>. It seems a bit out of touch with what your telling me with what template are. In effect, myMacro is only used there. Would it b a better idea to ditch the macro and have the macro body directly into the template text? (yes, myMacro has no params.)

It depends. When your code is finished, it is probably more efficient that the template only contains the template text.
But for testing the following makes sense.

title: xTemplate

\define  myMacro()
this code works but looks odd
\end

\define myMacro()
this code is  WIP but might look better in the end.
\end

<<myMacro>>

This gives you the possibility to easily test new code, without overwriting your "old but working" code. ... BUT BUT BUT ...
Once the new code works and is cleaner. You need to remove the old code. .. There should be only 1 "source of truth"

Otherwise you will have a nightmare to maintain your code .. trust me ;)

-mario


Soren Bjornstad

unread,
Jun 28, 2021, 10:51:43 PM6/28/21
to TiddlyWiki
On Monday, June 28, 2021 at 6:15:35 PM UTC-5 jn.pierr...@gmail.com wrote:
Thank you to both of you for your explanation. The information on the system tag was very helpful.

@Soren: you write tgis in your textbook:
[...]

I think PMario covered everything you asked very well, let me know if there's anything you still wanted to know. :)
Reply all
Reply to author
Forward
0 new messages