Variable/Macro no longer works in Tag-based listWidget Loop inside the Action-SendMessage widget code

85 views
Skip to first unread message

David

unread,
Apr 24, 2020, 12:53:26 PM4/24/20
to TiddlyWiki

The above tiddlyWiki file illustrates my question.


The "New" button in the TODO tiddler (there is one "New" button per context section) is supposed to create a new tiddler with tags automatically added. One of the tags "Task" is hard coded, and should be. The other tag is dynamic, and represents the current section Context (e.g. "Context_Home" or "Context_Out", etc.) and is placed in that code, hopefully, via a variable.

When you click on one of the "New.." buttons, you'll get a new tiddler draft, and notice that the current context is not one of the tags, but the variable declaration is: <<thisContext>>. That is what is not working.

This variable worked fine when the listWidget loop was looping over a text string of gathered contexts. But the filter has been changed to loop over tags now. Apparently that macro style syntax (i.e. <<thisContext>> ) doesn't quite work the same way now that the iterator is a tag.

Notice also that the variable works in the Button Display Text area, so we knot the variable is representing the right thing and is present at that point in the code.

Thanks for Looking!

<$button>
<$action-sendmessage $message="tm-new-tiddler"
 title="Task"
 tags="Task <
<thisContext>>"
 priority="3"
/>
New Task for <
<thisContext>>
</$button>


Eric Shulman

unread,
Apr 24, 2020, 1:49:04 PM4/24/20
to TiddlyWiki
On Friday, April 24, 2020 at 9:53:26 AM UTC-7, David wrote:
This variable worked fine when the listWidget loop was looping over a text string of gathered contexts. But the filter has been changed to loop over tags now. Apparently that macro style syntax (i.e. <<thisContext>> ) doesn't quite work the same way now that the iterator is a tag.  Notice also that the variable works in the Button Display Text area, so we knot the variable is representing the right thing and is present at that point in the code.
<$button>
<$action-sendmessage $message="tm-new-tiddler"
 title="Task"
 tags="Task <
<thisContext>>"
 priority="3"
/>
New Task for <
<thisContext>>
</$button>


You can't combine literal text and a variable reference *inside* of a quoted widget parameter.  Instead, you should define a macro to combine the values, and then refer to that macro as the parameter value, like this:

\define newTags() Task $(thisContext)$
<$button>
<$action-sendmessage $message="tm-new-tiddler"
 title
="Task"

 tags
=<<newTags>>

 priority
="3"
/>
New Task for <<thisContext>>
</$button>

Alternatively, you can use an "inline filter" to construct the tags parameter value, like this:

<$button>
<$action-sendmessage $message="tm-new-tiddler"
 title="Task"
 tags={{{ [[Task ]] +[addsuffix<thisContext>] }}}

 priority="3"
/>
New Task for <
<thisContext>>
</$button>

This avoids the need to define a separate macro to construct the string.  Note that the "[[Task ]]" syntax has a trailing space inside the brackets.  This is important since the value is supposed to be a *space-separated* list of tags.

Let me know how it goes...

enjoy,
-e

Mark S.

unread,
Apr 24, 2020, 1:54:37 PM4/24/20
to TiddlyWiki
This is actually a version of a problem that comes up frequently -- how to concatenate a variable or transclusion into a string.

This:

tags="Task <<thisContext>>"

will not work. It won't create a string with "Task" and the value of <<thisContext>> >

This is called concatenation. If you look for "concatenation" on TiddlyWiki.com there's at least one howto. Unfortunately, it's not the word that automatically springs to people's heads.

The two main ways around this problem is to use either {{{ }}} notation with a addprefix/addsuffix filter operator, or to use a helper macro. Macro's have substitution variables. A variable for a passed parameter looks like $variable$ and a substitution variable for an environmental variable looks like $(variable)$.

So, at the top of your tiddler create a macro like this:

\define thebutton()

<$button>
<$action-sendmessage $message="tm-new-tiddler"
 title
="Task"

 tags
="Task $(thisContext)$"

 priority
="3"
/>
New Task for <<thisContext>>
</$button>
\end

Then, down below replace the existing button code like this:

<<theButton>>

On Friday, April 24, 2020 at 9:53:26 AM UTC-7, David wrote:

David

unread,
Apr 24, 2020, 3:50:24 PM4/24/20
to TiddlyWiki
Yes, I think for this case, I like the inline filter option.  And it worked perfectly!

Thanks!

David

unread,
Apr 24, 2020, 3:52:37 PM4/24/20
to TiddlyWiki
I'm glad both of you guys chimed in.  I learned from both your perspectives.

TonyM

unread,
Apr 24, 2020, 7:04:16 PM4/24/20
to TiddlyWiki
David,

You mention context. My New tiddler button looks something like this

<$button>
<$action-sendmessage $message="tm-new-tiddler"
 title="Task" tags="Task"
 priority="3"
 domain={{!!domain}}
 project={{!!project}}
 client={{!!client}}
/>
New Task
</$button>

So basically new tiddlers are created with the same context (in fields) as the tiddler where I use the button. The view template displays the new button.

Regards
Tony

David

unread,
Apr 29, 2020, 10:57:37 AM4/29/20
to TiddlyWiki
Nice.  Thank you!
Reply all
Reply to author
Forward
0 new messages