Why does the conditional shortcut syntax not run in the widget?

I have created a small button to restore the problem I am experiencing, the button code is below. Theoretically, when the button is clicked, it triggers the judgement inside. And in case the judgement condition is true, it triggers the code inside further. But obviously this didn’t work. Even when I put the conditional shortcut syntax content outside, it doesn’t work.

<$let  tiddlerName=<<currentTiddler>>  >
<$button>
<$action-confirm $message="Whether to create a new series of child entries">
<$list filter="[[-info]] [[-toc]]" variable="suffixName">
<$action-createtiddler $basetitle={{{ [<tiddlerName>addsuffix<suffixName>] }}} tags=<<tiddlerName>>/>
</$list>
<%if [<tiddlerName>addsuffix[-toc]is[tiddler]] %>
<$action-setfield $tiddler={{{ [<tiddlerName>addsuffix[-toc]] }}} cluster="toc"/>
<$action-createtiddler $basetitle={{{ [<tiddlerName>addsuffix[-toc-adrift]] }}} tags={{{ [<tiddlerName>addsuffix[-toc]] }}} />
<%endif%>
<%if [<tiddlerName>addsuffix[-info]is[tiddler]] %>
<$action-setfield $tiddler={{{ [<tiddlerName>addsuffix[-info]] }}} cluster="book-info"/>
<%endif%>
</$action-confirm>
Create
</$button>
</$let>

Putting it outside.

<$let  tiddlerName=<<currentTiddler>>  >
<$button>
<$action-confirm $message="Whether to create a new series of child entries">
<$list filter="[[-info]] [[-toc]]" variable="suffixName">
<$action-createtiddler $basetitle={{{ [<tiddlerName>addsuffix<suffixName>] }}} tags=<<tiddlerName>>/>
</$list>
</$action-confirm>
<%if [<tiddlerName>addsuffix[-toc]is[tiddler]] %>
<$action-setfield $tiddler={{{ [<tiddlerName>addsuffix[-toc]] }}} cluster="toc"/>
<$action-createtiddler $basetitle={{{ [<tiddlerName>addsuffix[-toc-adrift]] }}} tags={{{ [<tiddlerName>addsuffix[-toc]] }}} />
<%endif%>
<%if [<tiddlerName>addsuffix[-info]is[tiddler]] %>
<$action-setfield $tiddler={{{ [<tiddlerName>addsuffix[-info]] }}} cluster="book-info"/>
<%endif%>
Create
</$button>
</$let>

Does this mean that the conditional shortcut syntax is just replacing the text or displaying the text and not executing the next judgement logic. I got the solution from AI using list widget which was commonly used before the advent of conditional shortcut syntax. So more than solving the problem, I would like to know what is being processed behind the conditional shortcut syntax and whether it can perform more code logic. Or maybe it’s just a problem in action-confirm.

I just tested the AI method using the list widget, but it still didn’t work. It seems this is a troublesome issue.

<$list filter="[<tiddlerName>addsuffix[-toc]is[tiddler]]">  
<$action-setfield $tiddler={{{ [<tiddlerName>addsuffix[-toc]] }}} cluster="toc"/>  
<$action-createtiddler $basetitle={{{ [<tiddlerName>addsuffix[-toc-adrift]] }}} tags={{{ [<tiddlerName>addsuffix[-toc]] }}} />  
</$list>  
  
<$list filter="[<tiddlerName>addsuffix[-info]is[tiddler]]">  
<$action-setfield $tiddler={{{ [<tiddlerName>addsuffix[-info]] }}} cluster="book-info"/>  
</$list>  

It’s a matter of timing…

When you push the $button, it performs ALL the $action- widgets. However, because you are using $action-confirm to create the initial "-toc" and "-info" tiddlers, it delays performing the initial $action-createtiddler handling until after you respond by pressing “ok” in the $action-confirm modal dialog. Thus, the subsequent conditional tests for ...is[tiddler] fail because the "-toc" and "-info" tiddlers don’t yet exist.

Fortunately, there is a technique that works to defer the evaluation and execution of the conditional <%if...> (or $list) content by splitting the $button actions into two parts.

The first part, which uses $action-confirm is contained directly in body of the $button widget.

The second part, which uses the conditional <%if...> (or $list) syntax, is contained in a separate macro that is invoked via $button actions=<<myactions>> syntax.

Like this:

\define myactions()
<%if [<tiddlerName>addsuffix[-toc]is[tiddler]] %>
<$action-setfield $tiddler={{{ [<tiddlerName>addsuffix[-toc]] }}} cluster="toc"/>
<$action-createtiddler $basetitle={{{ [<tiddlerName>addsuffix[-toc-adrift]] }}} tags={{{ [<tiddlerName>addsuffix[-toc]] }}} />
<%endif%>
<%if [<tiddlerName>addsuffix[-info]is[tiddler]] %>
<$action-setfield $tiddler={{{ [<tiddlerName>addsuffix[-info]] }}} cluster="book-info"/>
<%endif%>
\end

<$let  tiddlerName=<<currentTiddler>>  >
<$button actions=<<myactions>>>
<$action-confirm $message="Whether to create a new series of child entries">
<$list filter="[[-info]] [[-toc]]" variable="suffixName">
<$action-createtiddler $basetitle={{{ [<tiddlerName>addsuffix<suffixName>] }}} tags=<<tiddlerName>>/>
</$list>
</$action-confirm>
Create
</$button>
</$let>

When the $button is pressed, the inline $action-confirm is immediately invoked, waits for a user response, and then creates the initial "-toc" and "-info" tiddlers. It is only AFTER that processing is completed that the “actions=<<myactions>>” code is invoked, allowing the conditional tests to function as intended.

enjoy,
-e

1 Like

Thanks for the answer. Although I knew there was an actions parameter in the button, I never knew how and why it was used. Now I understand it.