Create tag with a space and a variable

Hi all,

I am trying to make a button that:

  1. creates a tiddler
  2. gives this tiddler a tag consisting of the word ‘ADDED’ followed by today’s date, with a space in between.

The most successful attempt so far is this code:

\procedure added()  
ADDED <<now DD-MM-YYYY>>
\end

\procedure actions()
<$wikify name="tx" text=<<added>>>
<$action-createtiddler $basetitle="Book Title" tags=<<tx>>/>
</$wikify>
\end

<$button actions=<<actions>>>Create new book record</$button>

This adds two tags, one ‘ADDED’ and one with the date.

How to solve this?

(I realise that a field ‘added’ with the date is a better approach, but I still want to know why all my attempts for such a simple thing fail.)

Greetings,
Sjaak

First: you can do this without $wikify by changing the <<added>> procedure to a function:

\function added() ADDED [<now DD-MM-YYYY>] +[join[ ]format:titlelist[]]
\procedure actions() <$action-createtiddler $basetitle="Book Title" tags=<<added>> />

<$button actions=<<actions>>>Create new book record</$button>

Switching to a function also makes it more convenient to add +[join[ ]format:titlelist[]], which is the key step you were missing. Breaking it down:

  • The $action-createtiddler treats all attributes that don’t begin with $ as the names of fields, and assigns whatever value you give the attribute as the new value of that field. Thus, your original code would create a new tiddler with tags: ADDED 19-2-2025. Note the lack of square brackets!
  • Although the tags field gets special handling in edit mode, behind the scenes, it’s just a field in title-list format — that is, a list of space-separated values where multi-word values must be [[surrounded in square brackets]].
    • This is more obvious if you look at the Fields tab of the tiddler info, usually available under the “more” dropdown in your tiddler toolbar; this will show you all the fields in use on a tiddler, including the special system fields you don’t normally see.
    • tags: ADDED 19-2-2025 will thus be parsed as two tags, “Added” and “19-2-2025”, rather than the single tag you want.
  • To get a single tag, you need to…
    1. join both elements with a space, and
    2. format:titlelist[] to add the necessary square brackets.

If you do want to keep your $wikify approach, here’s how I’d change it:

\procedure added()  
ADDED <<now DD-MM-YYYY>>
\end

\procedure actions()
<$wikify name="tx" text=<<added>>>
<$action-createtiddler $basetitle="Book Title" tags={{{ [<tx>join[ ]format:titlelist[]] }}} />
</$wikify>
\end
1 Like

I knew the space was the culprit, but I did not know how to disarm it. You gave two ways to do it, thanks!
I have to read up on functions etc.