action-setfields setting tags from a variable

72 views
Skip to first unread message

vpl

unread,
Mar 3, 2020, 6:19:01 AM3/3/20
to TiddlyWiki
Hi,

I want to action setting of tags when I click on a button
One of the tags has to comme from a variable that is entered by the user

In the code below the user gives a name for a play list (PL_name) and once it clicks on the button I would like to create a new tiddler "My new tiddler" with 2 tags
One is hard coded ("first-tag") the other is set to the value entered by the user

The code below does not work ... I'm not using the variable the right way ...

Some expert that could help me ?

Thanks in advance for your help
Regards

<$edit-text tiddler="playListTemplate" field="PL_name"/>

<$button actions="">Create a play list
<$action-createtiddler $basetitle="My new tiddler"  />
<$action-setfield $tiddler="My new tiddler" tags="first-tag {{playListTemplate!!PL_name}}"/>
</$button>

Mat

unread,
Mar 3, 2020, 6:32:39 AM3/3/20
to TiddlyWiki
Intuition tells me there's something fishy with

tags="first-tag {{playListTemplate!!PL_name}}"

My guess is you should put the argument as a separate macro and instead to tags=<<mymacro>> or some such. Possibly a $set to store the macroresult in some variable and then tags=<<myvariable>>

<:-)

Mat

unread,
Mar 3, 2020, 6:34:22 AM3/3/20
to TiddlyWiki
Oh, wait, this doesn't look right

<$button actions="">

That might override/disable the other actions, I'm not sure.

<:-) 

Eric Shulman

unread,
Mar 3, 2020, 6:58:37 AM3/3/20
to TiddlyWiki
On Tuesday, March 3, 2020 at 3:19:01 AM UTC-8, vpl wrote:
In the code below the user gives a name for a play list (PL_name) and once it clicks on the button I would like to create a new tiddler "My new tiddler" with 2 tags
One is hard coded ("first-tag") the other is set to the value entered by the user

In your code, you are using $action-setfield to set the tags to a literal text string:
<$action-setfield $tiddler="My new tiddler" tags="first-tag {{playListTemplate!!PL_name}}"/>
However, TiddlyWiki syntax doesn't evaluate this literal string to expand references within it.  Thus, the resulting tags are exactly what is in between the quotes.

Fortunately, there is a different widget, $action-listops, that uses a "$filter" parameter that IS evaluated and produces a space-separated list which is then assigned to the specified field.

The following will create a "tags" field that has the two tags you want.
<$action-listops $tiddler="My new tiddler" $field="tags" $filter="first-tag [{playListTemplate!!PL_name}]"/>

Note the use of *single* square brackets and curly braces in the filter.  The square brackets define a "filter run", and the curly braces retrieve the desired field value.

enjoy,
-e

Eric Shulman

unread,
Mar 3, 2020, 7:07:41 AM3/3/20
to TiddlyWiki
You can have both... inline action widgets AND actions="..."
The inline action widgets are processed first, followed by the widgets contained in the actions="..."

-e

vpl

unread,
Mar 3, 2020, 10:13:59 AM3/3/20
to TiddlyWiki
Thanks very much !!!

The option
<$action-listops $tiddler="My new tiddler" $field="tags" $filter="first-tag [{playListTemplate!!PL_name}]"/>
is working perfectly 

So responsive and accurate

Thanks a lot for your support

Vpl
Reply all
Reply to author
Forward
0 new messages