Field as part of an image url

81 views
Skip to first unread message

Glenn Dixon

unread,
Dec 28, 2020, 9:33:21 PM12/28/20
to TiddlyWiki

I've tried several different syntax options and I am obviously doing it wrong. So how do I get this image to display in a tiddler?


The isbn field isn't interpreting/parsing and I get a broken image link. I also tried something similar using the "<$image" syntax. I fear this will require a macro, in which case I may abandon the entire project, as the macro syntax makes all other TW syntax look like plain text to me...

Eric Shulman

unread,
Dec 28, 2020, 10:10:40 PM12/28/20
to TiddlyWiki
Macro syntax is actually quite simple.  Within the body of a macro, only two things happen:

1) replace instances of $param$ with the corresponding value passed as a macro parameter
2) replace instances of $(variable)$ with the corresponding value from a variable defined outside the macro

Other than these two actions, the content of a macro is simply "returned" and is inserted in place of the macro call itself.  The substituted content is then processed by the TWCore as if it had been directly entered where the macro occurred.

For example, if you define a macro like this:
and then invoke that macro like this:
<<makeimg "foo">>
the resulting content will be
Note that the parameter passed to the "makeimg" macro is literal text, so it's just enclosed in simple quotes. However, for your desired use-case, you want the parameter value to be retrieved from a tiddler field.  You might think to try writing: <<makeimg {{!!isbn}}>>.  Unfortunately, this won't work, because the <<macroname ...>> syntax doesn't directly handle the use of {{!!fieldname}} for specifying  the parameter value.  Fortunately, there is another way to invoke a macro, by using the <$macrocall .../> *widget* syntax, which DOES allow use of {{!!fieldname}} references to specify parameter values.  Thus, to achieve your goal, you can write:
<$macrocall $name="makeimg" isbn={{!!isbn}} />

When the above $macrocall is processed, the value stored in the tiddler field is retrieved and passed into the macro for substitution processing.  The resulting syntax is then "returned" and inserted in place of the <$macrocall .../> syntax, which is then processed by the TWCore to render the image.

Alternatively, instead of passing the field value as a parameter, you could retrieve the value as a *variable* before invoking the macro, and then reference that variable within the body of the macro definition, like this:
which would be invoked like this:
<$vars isbn={{!!isbn}}> <<makeimg>> </$vars>

Using either method, the result is the same: the value from the tiddler field is used to construct the desired URL for the [img[...]] syntax.

enjoy,
-e

Glenn Dixon

unread,
Dec 28, 2020, 11:24:01 PM12/28/20
to TiddlyWiki
Thank you, sir. I almost feel as if I could replicate a macro now! As it is, this will definitely make book cataloging/tracking, etc. much easier!

with-chatwin.png
Reply all
Reply to author
Forward
0 new messages