How to Setting Tags Dynamically

Working on a personal gaming notekeeping tool for tiddlywiki and hit an issue with setting tags on a new tiddler that I just can’t seem to solve.

I recognize I likely could pull this off by jumping into javascript but trying to do this without that if possible (if nothing else but to learn).

I’m trying to basically have a button that makes a new tiddler, uses the title of the current tiddler mangles it and puts that value as a tag on the new tiddler.

The code below works but the new tiddler ends up with the tags of
< < slugval > > (spaces only here in the post so it shows up)
Scene

It has to be something I’m not getting with substitution etc but just not grasping it.
Any help would be appreciated.

\define concatVal() <<slugval>> [[Scene]]

<$button>Test
<$set name=slugval filter="[all[current]slugify[]addsuffix[_thread]]">
<$set name="finalTag" value=<<concatVal>> >
      <$action-log />
     <$action-sendmessage $message="tm-new-tiddler" title="New Tiddler" text="Some Random Text" tags=<<finalTag>>/>
</$set>
</$set>
</$button>

Try this:

<$button>Test
<$action-sendmessage $message="tm-new-tiddler" title="New Tiddler" text="Some Random Text"
   tags={{{ [<currentTiddler>slugify[]addsuffix[_thread Scene]format:titlelist[]] }}}/>
</$button>

Notes:

  • You don’t need to use a concatVal macro to add " Scene" to the end of the contructed tag. Instead, you can include the literal " Scene" text within the addsuffix[...]filter operator that is already appending “_thread” to the currentTiddler title.
  • Instead of a separate <$set name=... filter="..."> widget, you can use an inline “filtered transclusion” (the tripled curly braces) to invoke the filter that constructs the tag text. Note that when the filtered transclusion occurs as the value of a widget parameter, only the first list item produced by the filtered transclusion is returned for use. For this specific use case, this is not a problem, since the specified filter is constructing a single text value (e.g., “[[nameoftiddler_thread scene]]”)
  • Using <currentTiddler> is slightly more efficient than all[current], as it directly looks up the current tiddler’s title, without having to first parse the current filter operand keyword value.
  • format:titlelist[] automatically adds [[ and ]] surrounding the constructed tag value, but only when it contains spaces.

enjoy,
-e

1 Like

First thank you so much for the aid and the explanation it’s helping my understanding of this.

Sorry if I wasn’t clear.
I acctually want 2 tags on the new thread.
I want the new tiddler to have the first tag be:
test-bed_thread (aka the title of the first tiddler with _thread)
and then Scene as a separate distinct tag.

Thanks

<$button>Test
<$action-sendmessage $message="tm-new-tiddler" title="New Tiddler" text="Some Random Text"
   tags={{{ [<currentTiddler>slugify[]addsuffix[_thread]] [[Scene]] +[join[ ]] }}}/>
</$button>

Notes:

  • Within the filtered transclusion for the tags parameter, provide filter runs for both desired tags, followed by +[join[ ]] to construct a single string for assigning to the tags field of the new tiddler.

-e

Thank you very much.
I was just beginning to realize this based on the example you gave me earlier.

Still wrapping my head around how intertwined the filter system is with all the other logic.

Thanks

@huntsfromshadow your approach is quite similar to what I use for the same functionality (creating a new tiddler with some static/hardcoded tags, and some other dynamic/calculated tags); I’ve taken the liberty of adjusting your initial code to work as (I guess) you intended:

\define concatVal() [[$(slugval)$]] [[Scene]]

<$button>Test
<$set name=slugval filter="[all[current]slugify[]addsuffix[_thread]]">
      <$action-log />
     <$action-sendmessage $message="tm-new-tiddler" title="New Tiddler" text="Some Random Text" tags=<<concatVal>>/>
</$set>
</$button>

The only thing you were missing was rendering the value of slugval as a variable, inside the macro (those $(...)$ you see in the code now).