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.

Ex:VeryOrdinaryDay/answer

18th August 2021 at 1:50pm

To show text only if a condition is true, we can use the list widget paired with a filter which outputs one item if the condition is met and nothing if it isn't:

<$set name=formattedToday value=<<now "0MM/0DD">>>
  <$list filter="[[UsHolidays]getindex<formattedToday>]" emptyMessage="Sadly, it's a very ordinary day today.">
    It's ''<<currentTiddler>>'' today!
  </$list>
</$set>

If we didn't want to use emptyMessage (or didn't know about it), we could use a second list widget that had the opposite condition. The opposite condition is somewhat more difficult to compose, as there is no filter operator to determine whether an index exists in a data tiddler. Instead, we can team up then, else, and is[blank]:

<$set name=formattedToday value=<<now "0MM/0DD">>>
  <$list filter="[[UsHolidays]getindex<formattedToday>]">
    It's ''<<currentTiddler>>'' today!
  </$list>
  <$list filter="[[UsHolidays]getindex<formattedToday>then[]else[holiday]!is[blank]]">
    Sadly, it's a very ordinary day today.
    </$list>
</$set>

That is, first get the value of the index. Then if that value is not empty (meaning the index existed), change the value to an empty one, and if the value is empty, change it to a non-empty one. Lastly, remove all empty values (the distinction between an empty value and a nonexistent one is explained in this exercise answer). The net effect is that the body of the $list widget is shown if getindex[] returns an empty value, and nothing is shown otherwise.

This thenelseis[blank] pattern may come in handy in other places as well.

Go to question: Ex:VeryOrdinaryDay