Syntax Query Conditional Shortcut

I am having a look at the conditional shortcut syntax (https://tiddlywiki.com/static/Conditional%20Shortcut%20Syntax.html) and am wondering if the following statement is allowed/valid?

I am trying to set the state-name to ‘Northern Territory’ if the state-code is ‘NT’.

<$let
<%if [{<selectedstatecode>}match[NT]] %>
     selectedstatename="Northern Territory"
<%endif%>
  locationTag={{$:/TLS/location}}
  typeTag={{$:/TLS/type}}
  cityTag={{$:/TLS/city}}
>
..
..
..
</$let>

OR should it be the following

<%if [{<selectedstatecode>}match[NT]] %>
     <$let
          selectedstatename="Northern Territory"
     >
<%endif%>

<$let
  locationTag={{$:/TLS/location}}
  typeTag={{$:/TLS/type}}
  cityTag={{$:/TLS/city}}
>
..
..
..
</$let>
</$let>

bobj

Neither of those is valid. You can not have additional tiddlytext running inside the LET widget. You can only set variables in it. Also, you cannot split open and closing tags like the second option. You cannot open the LET widget inside the conditional and then close it later outside the conditional.

Just like the LET widget, it only applies to what is between its open and close tags, so the conditional is only valid for what is inside of its open and close tags, so the closed LET widget tag is no longer referenced to its open tag, as it cannot be seen outside of the conditional statement.

Why not just set the selectedstatename directly with the filter:

<$let
    selectedstatename={{{ [<selectedstatecode>match[NT]then[Northern Territory]] }}}
    locationTag={{$:/TLS/location}}
    typeTag={{$:/TLS/type}}
    cityTag={{$:/TLS/city}}
>

Also, just one additional point for future reference, in a filter, you cannot use the open and closing curly brackets when using a variable like in your example:

You put: [{<selectedstatecode>}match[NT]]
Instead of: [<selectedstatecode>match[NT]]

2 Likes

Ah, thanks @CasparBooWisdom

Bobj