View template filter efficiency

I’ve been reviewing an older wiki that I recently updated to 5.3.8. It is using several view templates all starting with something like (different tag criteria in each):

<$list filter="[is[current]tag[taggymctagface]]">

I was wondering if that is still best practice? I was thinking that I should change it to something like:

<%if [<currentTiddler>tag[taggymctagface]] %>

I’ve noticed that <currentTiddler> appears to work the same as is[current] and all[current]. Is there a reason to pick one over the others?

<currentTiddler> directly retrieves the variable value, while is[current] and all[current] both need to parse the [current] param value before retrieving the variable value. Thus, <currentTiddler> is very slightly more efficient, but not in any way that you will notice for your view template usage.

I prefer using <currentTiddler> since I feel it is semantically much clearer as to what it is doing.

-e

3 Likes

Perhaps the only place you could gain efficiency, is if you move the current enhancements of the viewTemplate into the viewTemplate cascade mechanisms. This is so very dependant on what your existing enhancements do.

  • There is a strong argument not to bother unless you face performance problems because the gains may be minimal yet take a lot of effort to implement.

The ViewTemplateBody cascade (see $:/ControlPanel > Info > Advanced > Cascades > ViewTemplateBody) is the way to go when you want to completely replace the default tiddler body with alternative content.

However, if your objective is to add extra content to the default tiddler body, then using $:/tags/ViewTemplate with conditional logic (either $list or %if) is significantly easier to understand and implement.

-e

I agree, that was the feeling I was getting.

There doesn’t seem to be opinion of <$list> vs <%if%>, but the latter is clearer. It seems my original thinking was on the right track.

Thanks for the feedback. When working with TiddlyWiki there is so much functionality I’m always wondering if there is some hidden trick or something I’m missing!

There usually is, but it is not necessary :nerd_face:

Many of us had our <$list … > habits in place long before the conditional shortcut syntax <% if … %> came into being. And since it ain’t broke, we may not be fixing it until/unless prior work needs refactoring.

For new work, I do prefer <% if %> — especially for the ease of following up with an <% else %>. The <$list> version can lead to awkward surprises if you haven’t usually needed to add limit[1] to the end of the filter… but suddenly a solution that worked fine somewhere else ends up displaying your conditional content once for every tiddler in your wiki. :rofl:

For some more discussion use of older syntax for backward compatibility, see

Also I would add to this we tended to use list primarily for listing, but before we had “If conditionals” at most we had the reveal widget, which is unnecessarily complex for many cases, we ALSO used list for conditional display.

Now conditional display can be well served by the if statement, it does not reduce the power of the $list widget, it simply allows it to be used for its primary purpose of listing.

If I were giving advice to someone learning TiddlyWiki I would suggest both are important to the operation of TiddlyWiki and they both deserve your attention.

1 Like