This is a stripped-down version of a single section of Grok TiddlyWiki, optimized for fast loading and readability by search engines. Some features are missing.

For the full Grok TiddlyWiki experience, please visit the wiki version of this page.

Getting the Current Tiddler Right on Drafts

 26th September 2024 at 4:57pm

It's likely that you will often include content that depends on the value of the current tiddler in your tiddlers. This can sometimes get you in trouble if you're trying to see that content in the side-by-side preview while editing a tiddler. Specifically, the preview works fine if referring to fields on the current tiddler (since those will also be fields on the draft tiddler), but it doesn't work if the current tiddler's title is used to retrieve content from somewhere else (since the tiddlers you aren't editing won't have their content change because you're editing a draft).

For instance, imagine we are looking at a contact tiddler and we want to find all tiddlers that have a family list field containing the current contact. We might say:

<<list-links "[contains:family<currentTiddler>]">>

This will display OK on the standard ViewTemplate while viewing the tiddler, but will show no output in the preview when editing the tiddler, because the current tiddler at that point is actually called something like “Draft of My Contact”.

If this gets annoying enough to be worth fixing, there is an easy fix: we just need to check if the current tiddler is a draft tiddler, and if it is, set the current tiddler to the tiddler this is a draft of instead. The original tiddler can be found in the draft.of field of the draft.

<$tiddler tiddler={{{ [all[current]is[draft]then{!!draft.of}else<currentTiddler>] }}}>
    <<list-links "[contains:family<currentTiddler>]">>
</$tiddler>

(Recall: the then operator outputs its parameter if the input is non-empty, while the else operator outputs its parameter if the input is empty.)

Notice that with the pattern above, if you are relying on both the name of the current tiddler and the values of its fields, your changes to the fields won't appear until you save since the current tiddler is now changed to the original rather than the draft. If that's a problem, you can always set a variable other than currentTiddler to the value of the original tiddler, and use currentTiddler when referring to fields and the other variable when referring to the name.

Takeaways

Takeaways are not available in the static version of Grok TiddlyWiki. Visit the wiki version of this page to study takeaways.

↑ 8: Tips and Tricks