Parametised template blocks

Folks, With 5.3.x and the $parameters widget and $transclude widget improvements, I have finally developed a solution that allows you write a template block in a tiddler (even field), procedure/macro, or inside a widget.

  • The template content can be any “tiddlywiki script” or wikitext
    • Including internal pragma, import, functions procedures etc…
  • You can pass into the template any parameter/value you want into that block.
    • All you need to do is use the parameter name, as a variable inside your template.
  • There is also the opportunity to provide a display filter to conditionally display the rendered template.
  • Also access the location of the template or the procedure that enables it with custom variables.
  • Turn links in the content on or off, for printing etc…

Why?

  • This helps make template for multiple purposes and use them inline (bespoke) or make them reusable as a macro/procedure or tiddler.
  • Easly create mail merge or reusable layouts or forms.
  • Easily search for and find all template invocations using this method, regardless of the where the template is stored.

I thought before I share this solution I may present the concept and seek feedback at a high level.

  • What features would you like in a generic templating feature?
  • What problems have you encountered using content templates in the past?

To be able to respond, I think I’d need to see some examples of what you’ve already accomplished. I use a great deal of templating in TW, and haven’t found much friction in that process, so it’s not clear to me what you’re proposing to do.

Sure scott. Perhaps others will respond before I share too much. I wanted to call on peoples conceptual perspective before prejudicing it by presenting my examples, but perhaps triggering peoples conceptual thinking is not so easy in a forum like this.

Perhaps you could help by thinking what content do you like to use templates for? Eg

  • form letters
  • list items
  • display blocks
  • reusable code

A feature of my approach is you can use the same custom widget to “invoke” templates defined inline, in tiddlers, fields, procedures and as a result you have reusable and searchable mechanisium to find all such uses.

  • common features are then built into the custom widget to support smarter templates.
  • write once use many times.

Perhaps I can share some example template contents, before my solution. As soon as I shard the solution people will tend to focus on the details and code, when first I want to solicit general needs.

Here is an example of a letter template

\procedure download-link() <a href=<<url>> target="_blank"><<link-title>></a>
Dear <<salutation>> <<firstname>> <<lastname>>,

Thanks you for purchasing our product <<product>>. 

This message is just to let you know we have released new supporting software that is available free of charge at <<download-link>>.

;Features include;
# feature 1
# feature 2
# feature 3
# feature 4

Feel free to contact us by return email if you have any Questions.

I haven’t forgotten this discussion, @TW_Tones; but I’m suddenly very busy. I will try to get to this soon.

… for some very inappropriate value of “soon”. :frowning:

You asked how we use templates.

This smallish wiki, described in some detail in #9397, makes extensive use of templates. All the Members, Meetings, and Puzzles are handled by templates – and these make up the bulk of the content. None of them have text fields, just data. This is how I often work with TW.

http://scott.sauyet.com/Tiddlywiki/Demo/ClubDemo/v2/

Perhaps this relates to our offline subject @CodaCoder ?

  • section to template to section exchangability.

Thanks scot

Me too, but i tend to leave the text field free for adhock notes, long form notes or more details, and end up using it for that on a fair percentage of cases. Depends on the tiddlers function of course.

I do the same thing. This wiki doesn’t have any of that yet, but give it time! Another much larger one that I’d love to share, but will be significantly more difficult to anonymize, is built much the same way, with more customizations in the text fields.

1 Like