Icons with 'dynamic' text or numbers

I was intrigued by the Journal icon in the sidebar tab ( if you have it selected for display ) which shows the integer value of today’s date - I figured I might like to include something similar in my current project.

It’s fascinating…

The SVG code for the journal icon in $:/core/images/new-journal-button looks like this…please note that I truncated the path declaration - see …[truncated]… that’s not the bit I am interested in…

Note that the last line of the SVG declaration above includes a reference to the tiddlywiki now macro with args DD to indicate only the number of the day should be shown - also a transform to rotate the text a bit.

So in my project I am interested in indicating when tiddlers are due for review, the icon shown on each tiddler toolbar could include say the review frequency (in days) for that tiddler. Here is what I have managed so far… picture of toolbar on one of my tiddlers - green bell icon now displays a number…in this case -35 this is the value stored in the field called ‘interval3’ of this tiddler, 35 days until this tiddler requires review. I would prefer a positive value ( 35 rather than -35 ) for display purposes but I will come to that later.

Screenshot from 2023-06-05 17-34-29

I guess the Tiddlywiki scans all text during the wikification process including native SVG code and where it spots a tiddlwiki macro reference it does the necessary work to insert whatever the macro returns directly into the SVG code - I regard this as immensely powerful - Wow!

So in my prototype as witnessed by the above screen shot I have managed to ‘inject’ the value of the tidder field ‘interval3’ into the icon SVG code as I wished except for the fact that ‘interval3’ is stored in the tiddler as a negative integer which is intentional because it makes life easier when using the tiddlywiki operator ‘days’ however as previously mentioned, for display purposes on the toolbar I would prefer to display the positive value in this case 35 instead of -35.

In the tiddler that adds my icon to each tiddler toolbar I have…

Screenshot from 2023-06-05 22-42-14

The macro reviewButton sets the SVG icon for the tiddler and so transcludes the SVG code for the Green bell icon. My Green bell icon has been prepared to call a macro called ‘intervalReview’ instead of the TW macro now which appears in the Journal icon SVG shown above - the upshot is that the value of the tiddler field named interval3 ends up in the displayed SVG icon.

Footnote: Apologies for anyone who tried previously to make sense of this post, it has since been heavily edited. I found I was unable to post code containing macro statements, they ended up displaying incomplete. In the end I resorted to screen shots to display the code. For simplicity the above image of code shows the code after the Eric Shulman had kindly solved the problem I was having of converting a negative value of inteval3 to it’s positive of abs value for the purpose of display in the Green bell icon. Thanks again to Eric for now providing 2 solutions to problems encountered in this project.

You can use the TWCore abs[] math filter operator to adjust the value to be displayed, like this:

Instead of

<$set name="intervalReview" value={{!!interval3}}>

use

<$set name="intervalReview" value={{{ [{!!interval3}abs[]] }}}>

Side note:
Instead of using <$set name="intervalReview" value={{{ [{!!interval3}abs[]] }}}>,
you could write: <$let intervalReview={{{ [{!!interval3}abs[]] }}}>

1 Like

Thanks Eric, I had gotten close to that but not quite, still finding syntax a bit tricky.

In case you couldn’t figure this out from elsewhere, the trick is to use backticks. Single backticks put things in code <$set like this> and triple backticks above and below a block render

like this (so here I can actually show a ` single backtick)
as well as multi-line <<stuff>>

Cheers!

Thanks I will try, I tried the blockquote markup but that did not allow double angle brackets

<<macro>>

Yup but that does! :smiley: thanks

1 Like