Has the `$if` widget been removed from Tiddlywiki? And if so, is there an alternative?

I Googled about the use of conditional statements in Tiddlywiki and the results (especially the AI results) repeatedly return stuff about the $if widget and yet when I try to use it, the output in my tiddler comes as Undefined widget 'if'.

For reference, my Tiddlywiki version is 5.3.6.

The successor is the Conditional Shortcut Syntax introduced with v5.3.2, which looks like this:

<%if [{$:/info/url/protocol}match[file:]] %>
  Loaded from a file URI
<%else%>
  Not loaded from a file URI
<%endif%>
1 Like

AI is very fond of inventing plausible-looking syntax; your instinct to fact-check it was correct!

In this case, there’s a little more basis to its hallucinations than usual. Prior to the introduction of the canonical <% if %> syntax @pmario suggested, there was a third-party plugin by Evan Balster that used <$if></$if><$else-if></$else-if><$else></$else> syntax. Evan hasn’t been active in the TW community for many years, and I struggled to find a working mirror of his site, so here it is courtesy of the Wayback Machine, if you’d like to take a look.

If you prefer the way the plugin handles conditionals, it’s still possible to drag the title to import it into a wiki — but do note that it hasn’t been maintained in several years. I wouldn’t anticipate it breaking in a “modern” wiki; I was a long-time user myself and still had $if instances in my wiki as recently as 5.3.5. But for new users, I would recommend the conditional shortcut syntax present in core TW; you’ll find it much easier to get support.

1 Like

It is also very good in spreading “fake facts”. The other day it matched my Postal Code to a totally different town. That was an eye opener to me. You always have to check it, no matter how plausible it sounds.

2 Likes

Thank you both @pmario and @etardiff for your help. Much appreciated.

The <%if [[]]%> syntax works nicely.

It just felt weird having to use $list for something like this (I wanted to display a list of convenient links to all tiddlers tagged so and so, inside a template tiddler only if that template tiddler were currently being viewed in the story river, by checking if currentTiddler's value was the same as the name of the template tiddler).

1 Like

TW also has and if-macro, which was used in the vanilla CSS. I think we removed it. At least is should be removed.

I checked out that link and it oddly swaps “else” and “elze”, so it’s quite a strange artifact to come across… (I came late from Classic to TW5, so I don’t have any super-old TW5 wikis to check.)

That’s because JS (like most programming languages) won’t let you use a reserved keyword as an identifier. It’s also why you often see “className” where “class” might do.