This is a plugin that uses a ViewTemplate to add a footer to every tiddler that meets certain criteria. So I would like to pass to the macro (or custom widget if that’s indicated; I haven’t tried those yet, though) three items derived from every Tag that’s indicated by that criteria (more details about the criteria at the plugin’s site): the name of the tag, the previous item to the current tiddler in that Tag’s list, and the next item. I was thinking that I should supply all items, and might still, but that’s easily derived from the tag name.
But I don’t think there’s any way to store these in a specific tiddler: this is information found only at tiddler-render time.
Yes, that’s exactly what I’m looking to do. Right now my plugin has a ViewTemplate tiddler, and the plucky user can override that to change the markup. But that mixes together the logic for selecting the correct tiddlers to show with the markup to format them. I was thinking it might be a useful refactoring to extract the markup into a macro, pass it the correct data, and have it do the formatting. Then the user has a very clean way to change the markup: just override that macro. I’m just looking for a way to pass that data.
Good to know.
In this case, I have no JS code in the Plugin, only Tiddlywiki. I used the Plugin as the cleanest way of deploying this code together. And in fact, this question is very much in the spirit of that discussion. I’ve looked at a few plugins that use JS, and I’m confident I could do something like that for certain purposes, but I’m trying to learn what is the most idiomatic way of doing this in TW, or if there is even the facility to do so.
Yes, and I’m thinking of them the same way, I believe, as a collection of key-value pairs.
Some of that might well clean up my current implementation. I hadn’t seen select
, and will check it out.
Well, that’s a clear failure, I guess. I was trying hard to give as much information as I could. Here is a very slightly simplified version of the current ViewTemplate
:
tags: $:/tags/ViewTemplate
title: $:/plugins/ScottSauyet/WizardNav/ViewTemplate
type: text/vnd.tiddlywiki
<$set name="currentNavStep" value={{!!title}}>
<table class="wizard-nav">
<$list filter="[is[current]tags[]tag[Wizard]sort[]]">
<tr>
<td>
<$list filter="[enlist{!!list}] :else[tag{!!title}] +[before<currentNavStep>]">
<$link to=<<currentTiddler>>>« {{!!title}}</$link>
</$list>
</td>
<td>{{||$:/core/ui/TagTemplate}}</td>
<td>
<$list filter="[enlist{!!list}] :else[tag{!!title}] +[after<currentNavStep>]">
<$link to=<<currentTiddler>>>{{!!title}} »</$link>
</$list>
</td>
</tr>
</$list>
</table>
</$set>
(I just noticed a bug in this, which I’ll try to correct soon: it yields empty tables for non-matching tiddlers. It shouldn’t have any markup at all then.)
If I was guaranteed that [is[current]tags[]tag[Wizard]sort[]]
returned only one tag, then I could extract a macro leaving this view template something like this, which is almost certain to have incorrect syntax – I’m still learning – but should demonstrate the idea:
<$set name="currentNavStep" value={{!!title}}>
<$list variable="tag" filter="[is[current]tags[]tag{$:/plugins/ScottSauyet/WizardNav/config/TagName}first[]]">
<$set name="prev" value="[enlist{tag!!list}] :else[tag{!!title}] +[before<currentNavStep>]">
<$set name="next" value="[enlist{tag!!list}] :else[tag{!!title}] +[after<currentNavStep>]">
<<WizardNavFooter $prev$ $next$ $tag$>>
</$set>
</$set>
</$list>
</$set>
alongside an overridable macro something like this (same syntax warning, but probably more so!):
\define WizardNavFooter(prev, curr, tag)
<table class="wizard-nav">
<tr>
<td>
<$link to=<<prev>>« {{prev!!title}}</$link>
</td>
<td>{{tag||$:/core/ui/TagTemplate}}</td>
<td>
<$link to=<<next>>>{{next!!title}} »</$link>
</td>
</tr>
</table>
\end
The trouble is there can be more than one, and even if I clean up the syntax, I don’t know how I might pass something vaguely equivalent to [{prev1, next1, tag1}, {prev2, next2, tag2}, ...]
to the macro so that it could loop over the various records to create rows. And that’s what I’m looking for advise on. Is there any reasonable way to do that? Can people suggest good alternatives?
A title list can be represented as a string (e.g. “[[The Cat]] [[El Gato]]”) and then turned back into a title list via the
enlist
orenlist-input
filter operators. Title lists can be turned into strings through the used of thereduce
filter run expression possibly in association withformat:titlelist[]
.
Thank you. I don’t see any way to stretch that to cover this case. But I could well be missing the implication. Now that there’s more details here, can you see it working?
Thank you both! Even if I can never manage to do what I was hoping, I’m learning a lot.