Simple String and Variable Concatenation

This post is a wiki … So it can be edited by everyone logged in.

Please add more real examples here!

Building a tooltip from fields or variables using filtered transclusion

<$button tooltip={{{ Here in [{!!title}] changes [<changecount>] +[join[ ]] }}}>Test button</$button>

  • When you hover over the button the tooltip is displayed as text.

However if you use the same directly in wikitext
{{{ Here in [{!!title}] changes [<changecount>] +[join[ ]] }}}
It will appear as a missing tiddler link, but if you want plain text?.

  • This is often resolved using the text widget as follows;
    <$text text={{{ Here in [{!!title}] changes [<changecount>] +[join[ ]] }}}/>

An alternative it to create a template and use that to display the result of your filtered transclusion.

  • In a tiddler called “text” add <$text text=<<currentTiddler>>/>
  • Now add it to the filtered transclusion {{{ Here in [{!!title}] changes [<changecount>] +[join[ ]]||text}}}

Converting the core icons to be usable in CSS stylesheets

The core icons lack the xmlns namespace and can’t be used as-is for CSS background (here’s why). However, svg can be nested, and you can nest the core svg using concatenation with a svg that has the correct namespace. The following example show how to apply any core image as a CSS background.

In a tiddler with the tag $:/tags/Stylesheet:

\rules except dash list

[class^="$:/core/images"],[class^="$:/core/icon"]{
aspect-ratio:1/1;
background:center/contain no-repeat var(--url);
display: inline-block;
width:22pt;
}

<$list filter="[[$:/tags/Image]tagging[]]" variable="image">
[class="<<image>>"]{
<$text text={{{ [[--url:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="22pt" height="22pt">]][<image>get[text]else<image>][[</svg>')]]+[join[]search-replace:g[#],[%23]search-replace:g[
],[]]}}}/>
}
</$list>

Then write in a normal tiddler <i class="$:/core/images/add-comment" style.width="50px"/> to see the add-comment icon appear as a background. If you want to be able to change the color of the icon, you can either use a mask instead of a background image and set the color with the background color, or use concatenation to set a fill color.

Preventing de-duplication

Filters automatically discard earlier copies of the titles in a run (Dominant Append), this can cause issues if you try to concatenate words, for example :

{{{ [{!!title}] was created on [{!!created}] and was modified on [{!!modified}] +[join[ ]] }}}

Will output

New Tiddler created 20221225012543379 and was modified on 20221225012719154

The first “was” has been removed by the de-duplication. To prevent that, you can use the “=” sign :

{{{ =[{!!title}] =was =created =on =[{!!created}] =and =was =modified =on =[{!!modified}] +[join[ ]] }}}

This can get tedious if you have a lot of words, so to make things easier you can use " " to group several words :

{{{ =[{!!title}] ="was created on" =[{!!created}] ="and was modified on" =[{!!modified}] +[join[ ]] }}}

7 Likes

The part with Preventing de-duplication can be implemented using the new sustitute filter operator in 5.3.0p. See examples in

New Features in TiddlyWIki 5.3.0: The Substitute Filter Operator - Discussion - Talk TW

The above link is about the use of the substitute operator but we also now have https://tiddlywiki.com/#Substituted%20Attribute%20Values

In keeping with the above examples, substituted attribute values are similar to the “filtered transclusion”. The key difference is they only operate as the “value of an attribute”, following the =

<$button tooltip=`${ Here in [{!!title}] changes [<changecount>] +[join[ ]] }$` >See tooltip</$button>

<$link to=`${ Here in [{!!title}] changes [<changecount>] +[join[ ]] }$`/>

If does not work in macro param:"" but a macro can be called with the macrocall widget, and new ‘$transclude $variable’ and thus you can use “substituted attribute values”;

\define macro(text) $text$
<$macrocall $name=macro text=`${ Here in [{!!title}] changes [<changecount>] +[join[ ]] }$`>>

The above examples can also include inside the backticks $( vaname )$ as we used to only in macros.