Parsing attributes

I’m creating a widget and trying to pass to it a macro value: <$mywidget foreground=<<colour foreground>> >. Inside the widget javascript what I get is the transclude string, not the color ("<$transclude tiddler={{$:/palette}} index=“foreground”><$transclude tiddler="$:/palettes/Vanilla" index=“foreground”><$transclude tiddler="$:/config/DefaultColourMappings/foreground"/></$transclude></$transclude>")

How can I “execute” the value so I get the actual color string?

interesting, sorry i don’t have a solution - usually what i see people suggesting is to put it in a <$let> widget to evaluate it before it gets to your widget, but

<$let clr=<<colour foreground>>>
<$text text=<<clr>>/>
</$let>

still outputs the <$transclude> string and not the rgba() value.

When using a macro as the value of a widget parameter, it is not “wikified” (aka, “evaluated”). Except for replacing any $param$ or $(variable)$ references contained within the macro definition, the full text of the macro definition is passed along as the value of the widget parameter. Thus, using <$let clr=<<colour foreground>>> will have the same problem as described in the OP.

To “capture” the evaluated output of a macro into a variable and then pass the resulting output as a parameter value in another widget, you can use the $wikify widget, like this:

<$wikify name="clr" text="<<colour foreground>>">
<$mywidget foreground=<<clr>>/>
</$wikify>
2 Likes

Another approach is to provide the name of the colour “foreground” to the widget , for example colour=forground.

Then within the custom widget find the color code;

  • Using Erics method

I am looking into another approach, if I find it will give an example later :nerd_face:
Maybe in this same reply.

I found the color macro definition here $:/core/macros/CSS and moved it into my widget;

\widget $with.colour(colour) 
   \procedure get-colour() <$transclude tiddler={{$:/palette}} index=<<colour>> ><$transclude tiddler="$:/palettes/Vanilla" index=<<colour>> ><$transclude tiddler="$:/config/DefaultColourMappings/$name$"/></$transclude></$transclude>

<<get-colour>>
\end

<$with.colour colour=foreground/>

I changed the references to "$name$" ro <<colour>>