Setting attributes with multiple values

I have a macro where I try to create a div with an attribute that is a concatenation of several values. I can’t understand the rules of the different ways to reference values and can’t get it to work. Here is what I currently have

\define concat(str) $str$

\define svg(title, tags:"", width:100%, height:100%)
\whitespace trim
<$let tiddlerTags={{$title$!!tags}} tags=<<concat "<<tiddlerTags>> $tags$">>>
<div x-class=<<tags>> width=$width$ height=$height$>
<$transclude tiddler=<<__title__>> />
</div></$let>
\end

When calling like <<svg Test tags:foo>> the x-class attribute is not rendered properly (expecting it to have the tags of the tiddler and additionally foo)

Try using a filtered transclusion for concatening values:

\whitespace trim
\define svg(title, tags:"", width:100%, height:100%)
<div x-class={{{ [{$title$!!tags}] [<__tags__>] +[join[ ]] }}} width="""$width$""" height="""$height$""">
<$transclude tiddler=<<__title__>> />
</div>
\end

<<svg Test tags:foo>>

Thank you, it worked. Have to say that all this black magic about how to be able to do seemingly trivial evaluations is very confusing…

I tried to do another macro with a predefined tag (‘inverted’) that doesn’t work, I can’t even figure out how to start to debug this:

\define isvg(title, tags:"", width:100%, height:100%) 
<<svg $title$ tags:{{ ["inverted"] [<__tags__>] +[join[ ]] }}} width:$width$ height:$height$>>
\end```

You forgot one curly bracket, and ["inverted"] is not a valid syntax for a filter expression, instead you can simply write

{{{ "inverted" [<__tags__>] +[join[ ]] }}}

However you cant directly pass a filtered transclusion to a macro parameter when the macro is in the short syntax, use the long form for that :

\define isvg(title, tags:"", width:100%, height:100%) 
<$macrocall $name="svg" 
title="$title$" 
tags={{{ "inverted" [<__tags__>] +[join[ ]] }}} 
width="$width$"
height="$height$"
/>
\end

EDIT:

Since you are using a macro filtered transclusion may not be necessary, macro substitution could work … try this and let me know if it works :

\define isvg(title, tags:"", width:100%, height:100%) 
<$macrocall $name="svg" 
title="$title$" 
tags="inverted $tags$"
width="$width$"
height="$height$"
/>
\end

or

\define isvg(title, tags:"", width:100%, height:100%) 
<<svg $title$ tags:"inverted $tags$" width:$width$ height:$height$>>
\end

EDIT2: Nevermind, I forgot that you want to use a filter to get the tags. This wont work because the filter you pass in tags:“inverted $tags$” will resolve to the literal string “inverted {{$title$!!tags}}”, the filter expression wont be wikified

1 Like