A how to: protecting my code from my continous tiddler title changes

90 views
Skip to first unread message

Charlie Veniot

unread,
Apr 6, 2021, 10:46:53 PM4/6/21
to TiddlyWiki
G'day,

This is just one of my practices to fully take advantage of relink to protect my code from me and my continuous tweaking of tiddler titles.

Some sample code:

<$vars DataTid={{{ [<currentTiddler>addsuffix[ Data]] }}}
           EditorName={{Sheet Designer!!title}}>
<$vars selectedSheet={{{ [<DataTid>getindex[selected_sheet]] [<currentTiddler>!match<EditorName>] +[last[]] }}}
           bViewOnly={{{[<currentTiddler>!match<EditorName>then[yes]else[no]]}}}>

About that sample code:

In the "TiddlySheets" project I've got going on, my "Sheet Designer"  (or "Sheet Editor"; I am on the fence) is the tiddler in charge of creating and editing sheets (like "TreeSheets", not like spreadsheets).  The tiddler also serves a second function: as a transclusion template, so that if I want to "publish" a sheet in some tiddler,  I transclude the sheet (a data tiddler) using the "Sheet Designer" as transclusion template.

The code above says:  hey, if this code (or "TiddlyWiki scripting") is happening for current tiddler = "Sheet Designer", then behave for that context (i.e. allow editng of the sheet); if this code is happening for current tiddler = something other than "Sheet Designer" then behave for that context (i.e. show the view-only sheet.)

Back to discussion:

Originally, my code was as follows:

<$vars DataTid={{{ [<currentTiddler>addsuffix[ Data]] }}}>
<$vars selectedSheet={{{ [<DataTid>getindex[selected_sheet]] [<currentTiddler>!match[SheetEditor]] +[last[]] }}}
           bViewOnly={{{[<currentTiddler>!match[SheetEditor]then[yes]else[no]]}}}>

Then I changed the tiddler's name from "SheetEditor" to "SheetDesigner".

And then my tiddler stopped working correctly.  And it took me a while to realize:  the Relink plugin could not catch the "hard-coded" reference to "Sheet Editor" inside my code's filter.

Once bitten, twice shy.  I changed my code as per way above.

Pretty much wherever I refer to a tiddler, instead of referring to that tiddler by title, I refer to the tiddler by transclusion of the title, which the Relnk plugin never misses.

So "{{ThisTiddler!!title}}" instead of "ThisTiddler".

I am a tweaker by nature, and that will never change.

So I code as per my nature.  Or I quickly refactor my code when I momentarily forget about my nature.

Anyways, all of that in case any other tweakers out there want to max out the benefits of relink.

PMario

unread,
Apr 7, 2021, 5:38:03 AM4/7/21
to TiddlyWiki

Charlie Veniot

unread,
Apr 7, 2021, 9:18:32 AM4/7/21
to TiddlyWiki
G'day g'day,

Thanks for the reference!  That documentation is quite awesome.

Although not my cup of tea, I think the majority of folk will find pragmas and whitelisting are cherries on top of the sweet goodness that is relink.

Flibbles

unread,
Apr 7, 2021, 12:40:41 PM4/7/21
to TiddlyWiki
Yeah, the *match* operator isn't in the operator whitelist by default since match isn't exclusively used for tiddler titles. You can add it, but then if you're using *match* elsewhere, it may result in unexpected relinks. What you're doing probably is the best practice.

However, if you decide to make this code reusable by plugging it all into a macro, then EditorName could be a macro param, and using the *\relink* in that case would be most clear.

Glad to hear Relink is helping out.

-Flibbles

Charlie Veniot

unread,
Apr 7, 2021, 1:08:40 PM4/7/21
to TiddlyWiki
Helping out?

Oh heck, for the way my sponge works:  Relink truly is a godsend.

Uh, well, you would be the godsend?

The Relink angel?

The Relink fairy?
tooth-fairy-1.jpg

Well, let's say I gusheth with heaps of praise.


Flibbles

unread,
Apr 7, 2021, 4:04:46 PM4/7/21
to TiddlyWiki
Glad to hear it!

Also, one small thing: you could have your filter be [<currentTiddler>!match{Sheet Designer!!title}then[yes]else[no]] if you wanted to get around making a variable.

Charlie Veniot

unread,
Apr 7, 2021, 5:29:20 PM4/7/21
to TiddlyWiki
I was not awares I could slap a transclusion in a filter.

That is quite awesome.  Thanks !
Reply all
Reply to author
Forward
0 new messages