A Details Procedure in TiddlyWiki 5.3.5: Dynamically Create HTML5 Codes

TiddlyWiki works like a Text Substitution Engine. See how you can create a simple Details Procedure.

\procedure details(label, src, status)
<$let this-details=`<details $(status)$> 
<summary><$text text=<<label>>/></summary>
<div><$transclude $variable="src" $mode=block/></div>
</details>` >
<<this-details>>
</$let>
\end

Here are two examples:

<<details "Hi Details" "I am a details widget in TiddlyWiki">>

<$transclude $variable="details" label="TiddlyWiki" src={{TiddlyWiki}} status=open/>

Produces:

Note how the status is used.

Remarks:

  1. I use the solution as you may not find better one using procedure
  2. I do not recommend it! It is far from good practice!!
4 Likes

This is the old macro solution:

\define details(label, src, status)
<details $status$>
<summary><$text text=<<__label__>>/></summary>
<div><$transclude $tiddler=<<__src__>> $field=title $mode=block/></div>
</details>
\end

I think people use procedure to replace macro because macro is slower? I’m not sure where I see it.
So I’m curious about will this in the procedure

`<details $(status)$> `

as slow as traditional way in the macro

<details $status$>

Despite of this, I think the indentation in the procedure version is worser than the macro version.

I have no measure of performance, but I like to stick with a small and concise set of syntax rules.
In case of details, I myself like the macro solution, it is simpler to learn and maintain :wink:

I’m curious why you chose either macro or procedure. Why not write a custom widget? It naturally and automatically handles embedded content.

This was an example of text substitution.
I would welcome such a custom widget! I assume you will use $genesis inside a \widget.

Why write a new widget when someone has written a plugin for one already? Plugins — Utilities for TiddlyWiki

To explore the power of WikiText! :wink: