On Saturday, September 26, 2020 at 11:52:29 PM UTC-7, Bob Jansen wrote:
>
> For example, why does this not work?
> <$button>
> <$action-setfield
>      $tiddler="$:/TLS/exhibition_id"
>      $value={{!!exhibition_id}}
> />
> <!--append the exhibition_id to the exhibition id field in each artwork-->
> <$list filter="[tag[Mark]]">
>      <$action-setfield 
>           $field="exhibition_id" 
>           $value=<<TLSconcatenate {{!!exhibition_id}} 
> {{$:/TLS/exhibition_id}}>>
>      /> 
> </$list>
>
> Link Artworks to Exhibition
> </$button>
>

> The result is the string {{!!exhibition_id}} {{$:/TLS/exhibition_id}} 
> stored in the exhibition_id field of each artwork selected and not the 
> transcluded values.
> TLSconcatenate is a simple macro to concatenate two strings
> \define TLSconcatenate(head tail) $head$$tail$
>

A macro does NOT "parse" anything that you pass to it.  It only does TWO 
things:
   1) replace instances of $param$ with a value passed into the macro
   2) replace instances of $(variable)$ with a value defined outside of the 
macro

Macro calls (<<macroname param param ...>>) do not parse any of the 
parameters before passing them into the macro.
Thus, when you use {{!!exibition_id}} and {{$:/TLS/exhibition_id}}, the 
macro simply appends those two bits of syntax, unchanged.

It is up to the "calling context" to determine what happens with the result 
of a macro.
If the macro occurs directly in wikitext, then the result *is* parsed and 
rendered.
If the macro is used as the value of a widget parameter, it is *not* parsed.

This can lead to some confusion when trying to debug a macro:
If you invoke <<somemacro {{foo}} {{bar}}>> and display the results, the 
{{foo}} and {{bar}} transclusions are parsed
and replaced with their underlying values, so it can look like the macro 
does what you might be expecting.
However, if you use that same macro as a widget parameter (e.g., 
$value=<<somemacro ...>>) then the
the tranclusions are NOT processed and the macro results are just passed 
along to the widget 'as-is'.

For your specific use-case (concatenating the text from two transclusions), 
forget macros...
Instead, use an "inline filter" to construct the desired widget parameter 
value.

"inline filters" (aka "filtered transclusion") are surrounded by 
tripled-curly braces: {{{ ... }}}
and contain filter syntax, which is itself enclosed in a pair of square 
brackets: [...].

Within the filter syntax, transclusions, variables, and literal text use 
*single* brackets:
   {...} for transclusions
   <...> for variables
   [...] for literal text

Thus, the $value param of your $action-setfield widget could be written 
like this:
<$action-setfield 
   $field="exhibition_id" 
   $value={{{ [{!!exhibition_id}addsuffix{$:/TLS/exhibition_id}] }}}
/>

Hope this helps.

enjoy,
-e

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/c33a122d-1519-44c1-a23b-9ea6617744a3o%40googlegroups.com.

Reply via email to