Joining / Concatenating

Time to call in the support team.

HI Team,

I am having all sorts of difficulties concatenating stuff. I have been trying to concatenate strings and fields for two days now with limited success.

Please have a look at this code.

<$button>

<$set name="selectedstatecode" value={{$:/TLS/selectedstate!!state-code}} >
     <$list filter="[all[tiddlers]field:statecode<selectedstatecode>]">
          <$set name="selectedstatename" value={{!!statename}} >
               <$action-setfield $tiddler="$:/TLS/selectedstate" $field="state-name" $value=<<selectedstatename>> />
          </$set>
    </$list> 

<$set name="stateTag" value={{$:/TLS/selectedstate!!state-name}}>

     <$action-createtiddler 
          $basetitle={{{ [{$:/TLS/incremental}addsuffix[:]addsuffix{$:/TLS/selectedstate!!state-name}addprefix{$:/TLS/selectedstate!!state-code}] }}}
          tags="[[All Items]] [[<<stateTag>>]]"

The problem now is the line tags="[[All Items]] [[<<stateTag>>]]". According to what I read, this should work so that if the stateTag variable contains “South Australia” the resulting tiddler should be tagged with ‘All Items’ and ‘South Australia’.

But this is not happening, it gets tagged with All Items and <<stateTag>>

I am obviously doing something wrong but what could it be :slight_smile: ? Does it need a join or an addsuffix to get it to work? Or is there a transclusion trick?

Also, the documentation for the join operator is so minimal to be almost useless. It needs to contain examples of how to join stuff in various guises.

bobj

Two syntax issues here…

  1. Using tags="..." assigns a literal text value to the tags field. But you want a computed value. One way to do this is to use a “filtered transclusion” like this: tags={{{ ... }}}. The filter expression contained between the {{{ and }}} is automatically processed to compute the value to assign to the tags field.

  2. Within a filter expression, to get the value of a variable, you REPLACE the inner square brackets with angle brackets, like this: [<stateTag>]. The outer square brackets contain the “filter run”, while the inner square brackets indicate how to process the contents of that filter run, where square brackets surround literal text (e.g., [some text here]), angle brackets surround variable references (e.g., <somevariablename>), and curly braces surround tiddler field references (e.g., {!!somefieldname})

Note also that when filtered transclusion is used to specify a widget parameter value, only the FIRST item from the filter is used as the parameter value. Thus, to create a tags value that includes multiple items, you need to construct a value that joins all the items with spaces, and uses doubled square brackets surrounding any item that contains spaces itself.

Putting this all together, your parameter syntax should look like this:

tags={{{ [[All Items]] [<stateTag>] +[format:titlelist[]join[ ]] }}}

where the format:titlelist[] operator ensures that doubled square brackets are added around items that contains literal spaces, and the join[ ] operator then glues all the items together as a single text item whose value is a space-separated list of items.

enjoy,
-e

2 Likes

Thanks @EricShulman

Bobj

Worked perfectly @EricShulman .

I would not have got that without you :slight_smile:

As I go further into TW’s capabilities and my requirements, I realise there is an awful lot more to come across.

thanks again.

bobj