Colour SVG from field?

61 views
Skip to first unread message

TonyM

unread,
Jun 9, 2020, 8:01:44 AM6/9/20
to TiddlyWiki
Folks,

The Following will collor the SVG image in the transcluded tiddler

<span style="fill:blue;">{{$:/core/images/clone-button}}</span>

Is there a simple way to get the color from the local tiddlers color field?

I have tried a few methods and lost.

Thanks
Tony

Eric Shulman

unread,
Jun 9, 2020, 8:12:26 AM6/9/20
to TiddlyWiki
On Tuesday, June 9, 2020 at 5:01:44 AM UTC-7, TonyM wrote:
The Following will color the SVG image in the transcluded tiddler
<span style="fill:blue;">{{$:/core/images/clone-button}}</span>
Is there a simple way to get the color from the local tiddler's color field?

You can use a filter parameter to construct the style definition, like this:
<span style={{{ [{!!color}addprefix[fill:]addsuffix[;]] }}}>{{$:/core/images/clone-button}}</span>

Note: this can be simplified a bit more by omitting the trailing semi-colon, like this:
<span style={{{ [{!!color}addprefix[fill:]] }}}>{{$:/core/images/clone-button}}</span>

enjoy,
-e

TonyM

unread,
Jun 9, 2020, 7:51:03 PM6/9/20
to TiddlyWiki
Thanks Eric,

The lesson for me to take out of this is to "think outside the double curly braces". I actually mean that quite seriously.

In my original problem I asked this
`<span style="fill:{{!!color}};">{{$:/core/images/clone-button}}</span>`
and it did not work
A good strategy is to look outside the {{!!color}} as something I can replace, "fill:desired;" as you have done.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages