Some simple enough conditional code…
(and btw, <<alog...>>
is merely a wrapper over <$action-log.../>
)
<% if [<dom-data-link>match[macro-doc-back-btn]] %>
<<alog "go-back-btn" "dom-data-link top-var previous-var">>
...
<% else %>
<<alog "go-NOT-back-btn" "dom-data-link">>
...
<% endif %>
In the console I get output from both log calls and in both cases dom-data-link=macro-doc-back-btn
After an hour of hair pulling, I tried this, which is crazy-stupid, but hey, it works:
<% if [<dom-data-link>match[macro-doc-back-btn]] %>
<<alog "go-back-btn" "dom-data-link top-var previous-var">>
...
<% else %>
<% if [<dom-data-link>!match[macro-doc-back-btn]] %>
<<alog "go-NOT-back-btn" "dom-data-link">>
...
<% endif %>
<% endif %>
which kinda proves, not only is it hitting the else clause when it should not, but it then succeeds the next negated match: !match[]
on the very thing it just failed on. IOW, the completely redundant second <% if %>
makes the <% else %>
work as it should have worked all along.
I’ve never encountered anything like this before and I have a ton of if-match/if-!match
code that works just fine.
My brain is broken.
Here is the actual code in full: it’s an eventcatcher action for a button element:
\procedure go()
<% if [<dom-data-link>match[macro-doc-back-btn]] %>
<$let
top-var=<<stack-pop visited-stack>>
previous-var=<<stack-peek visited-stack>>
>
<<alog "go-back-btn" "dom-data-link top-var previous-var">>
<$transclude $variable="stack-push" stackname="visited-stack" value=<<top-var>> />
<$action-setfield $tiddler=<<data-tiddler>> $field=varname $value=<<previous-var>>/>
<% else %>
<<alog "go-NOT-back-btn" "dom-data-link">>
<$action-setfield $tiddler=<<data-tiddler>> $field=varname $value=<<dom-data-link>>/>
<<macro-doc-force-update>>
<% endif %>
\end go
The “fixed” version:
\procedure go()
<% if [<dom-data-link>match[macro-doc-back-btn]] %>
<$let
top-var=<<stack-pop visited-stack>>
previous-var=<<stack-peek visited-stack>>
>
<<alog "go-back-btn" "dom-data-link top-var previous-var">>
<$transclude $variable="stack-push" stackname="visited-stack" value=<<top-var>> />
<$action-setfield $tiddler=<<data-tiddler>> $field=varname $value=<<previous-var>>/>
<% else %>
<% if [<dom-data-link>!match[macro-doc-back-btn]] %>
<<alog "go-NOT-back-btn" "dom-data-link">>
<$action-setfield $tiddler=<<data-tiddler>> $field=varname $value=<<dom-data-link>>/>
<<macro-doc-force-update>>
<% endif %>
<% endif %>
\end go
The button:
<$eventcatcher tag=span selector="button.doc-link-btn" $click=<<go>> stopPropagation=always>
<button class="tc-btn-invisible doc-link-btn" data-link=<<doc-link-name>>><code><<doc-link-name>></code></button>
</$eventcatcher>