Invoking a callable from within a substituted attribute value

Substituted Attribute Values shows several ways to perform string substitution in attribute values. But I can’t find a way to invoke a macro, procedure, or function from within one. Is this available? Obviously that callable would have to return plain text if this is to be useful, but when it does, can I do so?

In another thread, I’m discussing creating dynamic SVGs. One of the chief actions involved is dynamically setting the fill and stroke colors for various nodes. And while I might have – as I typed the last sentence! – thought of an alternative way to solve this problem, I had been thinking that I would like to call out to some procedure, function, or macro to fetch the color part of an attribute value. I haven’t been able to find a way, and I don’t know if it’s just because I haven’t stumbled onto the correct syntax, or because it’s simply not possible. Any hints?

Is to use the filter syntax within it, because you can from inside a filter.

I call “Substituted attribute values”, “backtick attributes” for short.

A Macro

<$text text=`${ [<now YYYY>] }$ `/>
  • By the way the text widget is a good one for testing the results of “backtick attributes”
  • Use the same method for using functions and procedures within a filter, within “backtick attributes” filter format ${ filter }$

Yes, I just think you need the correct syntax.

See how the currently buttons accept the size parameter in transcludes, but there are other ways. Perhaps show us an example of an SVG and the values you want evaluated before display.

I think the right way to have dynamic values for SVGs is, to use the same method as we do with the core SVGs. Using the \parameters pragma and use transclusions to create them.

See the <<size>> variables

Using a parametrized transclusion eg: <$transclude $tiddler="$:/core/images/close-all-button" size="2em"/>


The main problem with SVGs like this is, that they cannot be edited by SVG editors like Inkscape anymore, since they do not know about <<size>> variables. – It may be possible to tell them, by scripting Inkscape. But I do have no clue about that.

I’m working on a workflow to import Lucide icons into TW. It will contain several external helper scripts, to convert standard SVGs into .tid files with parameters. – But that’s not finished yet

Thank you. I must have been quite tired when I posted this question. I tried all sorts of variants, and when I saw you’re answer, my response was, “Well that’s the first thing I tried. It didn’t work for me.”

And I tested again, and it still failed:

<a href="http://example.com/${ [<now YYYY-0MM-0DD>] }$/data">Testing</a>

yielding

<a href="http://example.com/${ [<now YYYY-0MM-0DD>] }$/data">Testing</a>

Then I had a shamefaced realization: “D’oh. Backticks!”. I was testing with double-quotes.

:blush:

When I switched to backticks:

<a href=`http://example.com/${ [<now YYYY-0MM-0DD>] }$/data`>Testing</a>

it worked just fine:

<a href="http://example.com/2024-03-30/data">Testing</a>

Thank you for the response. It helped shake me from my blind spot.

I saw that when looking at the core, of course. But if this goes the way I think it might, I could end up with dozens – even hundreds – of these. I really don’t want to make them all parameters; I’d rather invoke a function/macro/procedure.

Also, many of them skip end tags. I know that TW handles that, but it would likely cause problems for other tools.

However, you could always edit the generated SVG. Right-click > Inspect > Edit as HTML > Select all > Copy. Then you’d have to substitute back in the <<size>> parameter, but that should not be too difficult, and we could always script both to- and from- conversions.

I look forward to seeing it, or at least to seeing the results. Please include all end tags!

In the few I’ve looked at, there has been only a size parameter. Are there other parameters we use?

For the Lucide icons, there may be a “background-color” and a “stroke-width” or something similar. Not sure yet

If we want to move between Inkscape and tiddiwiki and back we need a lossless type of transfer. It is however possible to have svg text generated that has the tiddlywiki script evaluated but not rendered to svg which could be returned to an svg editor.

I suspect we could also uses a difference engine

th-1689722140

?

1 Like

Ada lovelace and Babbage - at London’s natural history museum?

Yeah those were the days! No GPU, no SSD, no mouse, screen or keyboard. Hell, no electricity. “Kids, in my day, we had to crank if we wanted to watch cat videos!”

1 Like