[TW5] use reveal for showing/hiding a button depending on if tiddler with a specific name does exist?

910 views
Skip to first unread message

Hans Maulwurf

unread,
Jul 1, 2016, 6:20:03 AM7/1/16
to TiddlyWiki
The title says it. I want to use the reveal widget to show/hide a button when a tiddler is there or not. Best would be if the tiddlername could be in a variable.

PMario

unread,
Jul 1, 2016, 8:34:17 AM7/1/16
to TiddlyWiki
Hi Hans,


On Friday, July 1, 2016 at 12:20:03 PM UTC+2, Hans Maulwurf wrote:
The title says it. I want to use the reveal widget to show/hide a button when a tiddler is there or not. Best would be if the tiddlername could be in a variable.

Imo the reveal widget can't do it, since it has no parameter for this behaviour. But the list-widget can.

In my example the tiddler named: a   needs to exist. ... if it has the field created, it does exist. The button widget is just an example.

<$list filter="[[a]has[created]]"><$button to=HelloThere>...click</$button></$list>

for more info see: http://tiddlywiki.com/#Filter%20Operators:%5B%5BFilter%20Operators%5D%5D%20%5B%5Bhas%20Operator%5D%5D%20%5B%5Bhas%20Operator%20(Examples)%5D%5D

It would be possible to create a macro eg: myButton   and tag it $:/tags/Macro

\define myButton(exists)
<$list filter="[[$exists$]has[created]]"><$button to=HelloThere>...click</$button></$list>
\end


usage:

<<myButton a>>


have fun!
mario

Hans Maulwurf

unread,
Jul 11, 2016, 8:40:53 AM7/11/16
to TiddlyWiki
Why does this not work? I enter in the edit-field a tiddler name that surely exists

Titel: <$edit-text tiddler='$:/tmp/NewISMSElement' field='name_base' class='tc-edit-texteditor'/>

<$list filter="[{{$:/tmp/NewISMSElement!!name_base}}has[created]]"><$button to=HelloThere>...click</$button></$list>

Jeremy Ruston

unread,
Jul 11, 2016, 8:43:21 AM7/11/16
to tiddl...@googlegroups.com
Hi Hans

There’s one syntax problem that jumps out: you just need single curly braces inside the list filter:

Titel: <$edit-text tiddler='$:/tmp/NewISMSElement' field='name_base' class='tc-edit-texteditor'/>

<$list filter="[{$:/tmp/NewISMSElement!!name_base}has[created]]"><$button to=HelloThere>...click</$button></$list>

Best wishes

Jeremy

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/8c7560c0-fa54-4253-a6f0-fc70bf358b63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hans Maulwurf

unread,
Jul 11, 2016, 9:16:27 AM7/11/16
to TiddlyWiki
Great, thanks Jeremy

Hans Maulwurf

unread,
Jul 13, 2016, 10:59:01 AM7/13/16
to TiddlyWiki
ok, one last question

how do i give the variable "basename" to the inner macrocall inside the second/nested set??

<$set name="basename" value={{$:/isms/tmp/NewISMSElement!!name_base}}>
<$set name="elementID" value=<<getElementID <<basename>> >> >

</$set></$set>


Jeremy Ruston

unread,
Jul 13, 2016, 11:58:39 AM7/13/16
to tiddl...@googlegroups.com
Hi Hans

how do i give the variable "basename" to the inner macrocall inside the second/nested set??

You’ll have to use an inner macro that composes the arguments to getElementByID using text substitution:

\define inner()
<$set name="elementID" value=<<getElementID """$(basename)$""" >> >
...
</$set>
\end
<$set name="basename" value={{$:/isms/tmp/NewISMSElement!!name_base}}>
<<inner>>
</$set>

Best wishes

Jeremy



--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Jed Carty

unread,
Jul 13, 2016, 11:58:56 AM7/13/16
to TiddlyWiki
As long as the macrocall is inside something that defines BaseName (and it is), than you can just put <<BaseName>> or $(BaseName)$ in the definition of the getElementID macro. Something like this works:

\define getElementID() some_prefix_$(BaseName)$


<$set name="basename" value={{$:/isms/tmp/NewISMSElement!!name_base}}>
<$set name="elementID" value=<<getElementID>> >

</$set></$set>

But you may be able to do this in an easier way like this:

<$list filter='[{$:/isms/tmp/NewISMSElement!!name_base}addprefix[some_prefix_]]' variable=elementID>
Some wikitext here that uses <<elementID>>
</$list>

You can also use the set widget instead of a list, but the problem with that is if there are any spaces in the elementID than it will add [[ and ]] to the start and end of the id. And if you have a more complex way of creating your ids than you may have to do something more interesting.

Mark S.

unread,
Jul 13, 2016, 12:00:22 PM7/13/16
to TiddlyWiki
Unfortunately, I've never found it possible to pass a macro with a parameter inside another widget . You need to wrap it in a wrapper so the parameter is hidden. This worked for me, but I don't have your test data, or know how you're planning to use the results:

\define baseElem() <$macrocall $name=getElementID basename=$(basename)$/>

<$set name="basename" value={{$:/isms/tmp/NewISMSElement!!name_base}}>
<$set name="elementID" value=<<baseElem>> >

</$set></$set>

Good luck!
Mark

Hans Maulwurf

unread,
Jul 14, 2016, 5:42:09 AM7/14/16
to TiddlyWiki
thanks guys, this helped me till the next problem ^^

\define basename() {{$:/isms/tmp/NewISMSElement!!name_base}}
\define elementid()
<$macrocall $name="macroGetElementID" fullName=$(basename)$/>
\end
\define elementtitle()
<$macrocall $name="macroGetElementTitle" fullName=$(basename)$/>
\end

Titel: <$edit-text tiddler='$:/isms/tmp/NewISMSElement' field='name_base' class='tc-edit-texteditor'/>

<$list filter="[<elementid>!has[created]]">
<<currentTiddler>>
    <$button to=<<elementid>>>
        not yet created ... create it!
    </$button>
</$list>


how do I use the text from the macro "elementid" as a tiddler-name in the filter?

Jed Carty

unread,
Jul 14, 2016, 5:55:42 AM7/14/16
to TiddlyWiki
Macros work by text substitution, so it probably isn't something you can do directly. If what you want to do is possible than you can probably do it in a much simpler way, but you can't use a macro that uses widgets in a filter like that.

Hans Maulwurf

unread,
Jul 14, 2016, 6:05:27 AM7/14/16
to TiddlyWiki
Ok, I think you're right. I try to explain what I want to do ^^

I want an input-field where I type in a string like "B 2.5 some text bla".

This whole string has to be splitted into "B2.5" (so just the first two parts without space) and all the rest "some text bla".

If there is NO tiddler with the name "B2.5", I need the button "create this tiddler" and create 3 tiddlers  like this: where <name_base> should bethe "B2.5"

The tiddlers later should be filled with some fields and contents (but i would be glad if the empty tiddlers with the right names would be created by now)

    <$button>
        <$list filter="[<name_base>addsuffix[_1]] [<name_base>addsuffix[_2] [<name_base>addsuffix[_3]]">
            <$action-maketid tags="testmaketid" isms_test="text from a field" $navigate="hide"/>
        </$list>
        Make Tiddlers
    </$button>


Jed Carty

unread,
Jul 14, 2016, 6:43:24 AM7/14/16
to TiddlyWiki
That is possible using list widgets and some filtering. I will get back to you about this later because I just found out that the person I lined up to watch my dog while I am in England can't help me and I need to get that taken care of.

Hans Maulwurf

unread,
Jul 14, 2016, 2:35:06 PM7/14/16
to TiddlyWiki
Really? Wow, I'm trying for almost 4 days to do this with filtering. I'm looking forward for your hints :)

c pa

unread,
Jul 14, 2016, 6:42:52 PM7/14/16
to TiddlyWiki
Try something like the following:

\define Do_Some_Buttons(item_one, item_two)
    <$list filter="[all[$item_one$$item_two$]is[tiddler]]" emptyMessage="""
       Button to create tiddler named "$item_one$$item_two$"

   """>
         Hey it exists already
    </$list>
\end

\define Make_Something(text)
    <$set name="Item_One" filter="$text$ +[nth[1]]">
    <$set name="Item_Two" filter="$text$ +[nth[2]]">
        <<Item_One>> <<Item_Two>>

        <$macrocall $name="Do_Some_Buttons"
            item_one=<<Item_One>>
            item_two=<<Item_Two>>
        />

    </$set>
    </$set>
\end

`<<Make_Something "B 2.5 some text bla">>`
<<Make_Something "B 2.5 some text bla">>

Hans Maulwurf

unread,
Jul 15, 2016, 1:50:15 AM7/15/16
to TiddlyWiki
c pa, thanks for your help. This seems to do nearly what I need. But it's the point, that I have an input-field <$edit-text tiddler='$:/isms/tmp/NewISMSElement' field='name_base' class='tc-edit-texteditor'/> and when I use
<<Make_Something {{$:/isms/tmp/NewISMSElement!!name_base}}>>

it doesn't recognise the text of the input, it uses "{{$....}". So the space is not removed. I think this is the point Jed mentioned before that macros work by substitution.

c pa

unread,
Jul 18, 2016, 7:11:14 PM7/18/16
to TiddlyWiki
Hans,

Yes. the shortcut macro call method does not allow you to pass evaluated parameters. You need to use the long form macro call method

<<Make_Something {{$:/isms/tmp/NewISMSElement!!name_base}}>> does not work

<$macrocall $name="
Make_Something" thing={{$:/isms/tmp/NewISMSElement!!name_base}} /> will work

Eric Shulman

unread,
Jul 18, 2016, 9:31:51 PM7/18/16
to TiddlyWiki
I just tested the following directly on www.TiddlyWiki.com:

\define thismacro(arg)
arg
="$arg$"
\end

<$edit-text tiddler="temp" field="stuff"/>
<<thismacro {{temp!!stuff}}>>

and it works just fine to use the transclusion in the macro syntax.

You can even use *named* arguments if you want, like this:

\define thismacro(arg1,arg2)
arg1
="$arg1$"
arg2
="$arg2$"
\end

<$edit-text tiddler="temp" field="stuff"/>
<$edit-text tiddler="temp" field="otherstuff"/>
<<thismacro arg1:{{temp!!stuff}} arg2:{{temp!!otherstuff}}>>

enjoy,
-e

c pa

unread,
Jul 19, 2016, 11:01:16 AM7/19/16
to TiddlyWiki
Eric,


>> and it works just fine to use the transclusion in the macro syntax.

# You are absolutely right.
# There are edge cases where things don't work as expected
# My brain can't remember what the edge cases are
# Since debugging the source of the error takes longer than writing the code, and I write complex code, I've adopted the following practices
#* I use <$macrocall $name="macroname" /> rather than <<maconame>>
#* I pass all variables as parameters . . . $variablename$ rather than $(variablename)$
#* I always assign a variable="loop variable name" in my $list calls
#* I use <<loop variable name>> or $currentTiddler$ rather than <<currentTiddler>>

Granted. It takes way longer to write the code. And so way longer to whip up quick solutions. So this methodology stinks for on the fly fixes.
Reply all
Reply to author
Forward
0 new messages