Invokde procedure from button widget but no action widgets inside procedure

I am trying to invoke a procedure from a button widget but the invoked procedure does not have any action widgets.

Basically, we only want to initiate a backlinks display when the user clicks the button. That way we don’t waste computer resources displaying something not required.

Code:

ViewTemplate

<$list filter="[<currentTiddler>tag[Gun Type]]" >
<$button actions=<<TLSbacklinks>> >
Click to see backlinks
</$button>
</$list>

Procedure code

<!-- EXTRACTS BACKLINKS FROM THE CURRENT TIDDLER -->
\procedure TLSbacklinks()
<$list filter="[all[current]backlinks[]]" counter="numberofbacklinks" emptyMessage="There are no links to this record" >
<% if [<numberofbacklinks-first>match[yes]] %>
This record is linked from the following:
<br>
<% endif %>
<<TLSdisplaylinks>>

</$list>
\end

Can’t find any way of doing this.

bobj

Use the $button to set a $:/temp tiddler to “yes”, and then use that $:/temp tiddler’s value to control when to show the output.

Like this:

<$let temp=<<qualify "$:/temp/showbacklinks">>>
<$list filter="[<currentTiddler>tag[Gun Type]]">
<$button set=<<temp>> setTo="yes">Click to see backlinks</$button>
<%if [<temp>text[yes]] %><<TLSbacklinks>><%endif%>
</$list>
</$let>

Note that <<qualify "$:/temp/showbacklinks">> will create a separate $:/temp tiddler for each tiddler in which it is used so each tiddler’s backlinks display can be controlled independently.

-e

This is also commonly done using the reveal widget. One advantage is it can open and close at seperate location in the tiddler (or in the wiki).

However in addition to @EricShulman’s solution there is another way using the popup and testing for its tiddlers existance.

\procedure  TLSbacklinks()
<$list filter="[tag[About]]"><br><$link/></$list>
\end 

<$let temp=<<qualify "$:/temp/showbacklinks">> >
<$list filter="[<currentTiddler>tag[Gun Type]]">
<$button popup=<<temp>> class="tc-btn-invisible tc-tiddlylink">
<%if [<temp>has[title]] %>
   <kbd>Click to hide backlinks</kbd>
   <<TLSbacklinks>>
<%else%>
   <kbd>Click to see backlinks</kbd>
<%endif%>
</$button>
</$list>

This also demonstrates another look, CSS could stop its centering

Bugger, I was on the right track. I just couldn’t see how to trigger the procedure once the temp tiddler was set to Yes. Didn’t know about the qualify macro.

Thanks @EricShulman

Bobj

@TW_Tones , I seem to remember reading something a while ago hat $ reveal was being deprecated and being replaced by %if. Then sometime later, @pmario commented on a post that that was wrong.

Can someone please confirm or otherwise.

Bobj

even if it were deprecated you can possibly still use it for a decade, however it does not really have a replacement yet as it includes animation that nothing else does.

you can do the same with a list and if statements. you could even extract the if I put inside the button.

enjoy

We can not deprecate reveal yet, since we can not fully replicate its functionality yet. eg: popups, animation and so on.

Many places in the current UI can be replaced by the conditional %if statement, which gives a cleaner more semantic DOM structure.

The main problem with reveal was, that is often was used as an if, but it creates a DOM element, that is basically just “overhead” if the reveal is in “closed” state. – And we have many of them, which also make custom styling more difficult. That’s one reason, why we want to reduce them.

1 Like

So, in short, don’t use $reveal for new code, unless the animations, etc. are essential. Use <% if %> and friends when you can.