[TW5] Hide or Show Button when tiddler exists

96 views
Skip to first unread message

TonyM

unread,
Aug 3, 2017, 11:35:19 PM8/3/17
to TiddlyWiki
Hi Folks,

I would be greatful for some guidence on how to Hide or Show Button when tiddler exists/or not

I have some buttons, defined in macros, which I call and use a parameter and currentTiddler to name a second tiddler on which I wish to act.

 eg;
\define editsubtiddler(type)
<$button tooltip="Edit content in Separate tiddler">
<$action-sendmessage $message="tm-edit-tiddler" $param="$(currentTiddler)$ - $type$"  />
{{$:/core/images/edit-button}}
</$button>
\end

The above is in fact referenced via a tabs template view.

My Question
How best can I display the result of such macro ie the button, only if the tiddler does not yet exist, and in other cases only if the named tiddler exists?

Idealy this would be inside the abvove macro to keep elsewhere simple.

If I am to use a filter outside the macro I am concerned it will fail given the variables involved.

Thanks in Advance


More generaly,
I am making more progress each day with what still seems an art form of TiddlyWiki design, rather than a science. I have come to realise my penchant for reusable code and self referenceis is making it harder for me. Most examples I find use literal tiddler names etc... in the macro/widget etc..., when I am always trying to generalise so the macro would work in any similar tiddler.

I am greatful for the support at this point but will be contributing back soon.

Regards
Tonym

Eric Shulman

unread,
Aug 4, 2017, 12:26:40 AM8/4/17
to TiddlyWiki
On Thursday, August 3, 2017 at 8:35:19 PM UTC-7, TonyM wrote:
I would be greatful for some guidence on how to Hide or Show Button when tiddler exists/or not
I have some buttons, defined in macros, which I call and use a parameter and currentTiddler to name a second tiddler on which I wish to act.

My Question
How best can I display the result of such macro ie the button, only if the tiddler does not yet exist, and in other cases only if the named tiddler exists?

You can use a <$list> widget with the "is[tiddler]" or "is[missing]" filter to test if a tiddler exists or not. Something like this:

\define editsubtiddler(type)
<$list filter="[all[current]is[tiddler]]">

   
<$button tooltip="Edit content in Separate tiddler">
     
<$action-sendmessage $message="tm-edit-tiddler" $param="$(currentTiddler)$ - $type$"  />
     
{{$:/core/images/edit-button}}
   
<
/$button>
</
$list>
\end
 
enjoy,

-e
Eric Shulman
TiddlyTools.com: "Small Tools for Big Ideas!" (tm)
InsideTiddlyWiki: The Missing Manuals

TonyM

unread,
Aug 4, 2017, 2:28:10 AM8/4/17
to TiddlyWiki
Thanks Eric,

As you can see in my example the name of this tiddler I am testing for is "$(currentTiddler)$ - $type$"
Can you show me how to specifiy this in the filter, because this is where I still get it wrong.

Thanks in Advance

Eric Shulman

unread,
Aug 4, 2017, 3:29:25 AM8/4/17
to TiddlyWiki
On Thursday, August 3, 2017 at 11:28:10 PM UTC-7, TonyM wrote:
As you can see in my example the name of this tiddler I am testing for is "$(currentTiddler)$ - $type$"
Can you show me how to specifiy this in the filter, because this is where I still get it wrong.

To provide a specific title (other than the currentTiddler value), use "[title[sometitle]...]" instead of "[all[current]...]"
For your purposes, since both $(currentTiddler)$ and $type$ are replaced by their values *before* the filter is processed, you can write something like this:

<$list filter="[title[$(currentTiddler)$ - $type$]is[tiddler]]">

-e

TonyM

unread,
Aug 4, 2017, 3:34:19 AM8/4/17
to TiddlyWiki
Thanks Soo much Eric,

In this case I discovered the answer 3 seconds after you posted., but before I saw your answer.

Another mile stone for me.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages