On Monday, December 28, 2020 at 6:33:21 PM UTC-8 [email protected] wrote:

> 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?
> [img[https://covers.openlibrary.org/b/isbn/{{!!isbn}}-M.jpg]]
> 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...
>

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:
\define makeimg(isbn) [img[
https://covers.openlibrary.org/b/isbn/$isbn$-M.jpg 
<https://covers.openlibrary.org/b/isbn/%7B%7B!!isbn%7D%7D-M.jpg>]]
and then invoke that macro like this:
<<makeimg "foo">>
the resulting content will be
[img[https://covers.openlibrary.org/b/isbn/foo-M.jpg 
<https://covers.openlibrary.org/b/isbn/%7B%7B!!isbn%7D%7D-M.jpg>]]

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:
\define makeimg() [img[https://covers.openlibrary.org/b/isbn/$(isbn)$-M.jpg 
<https://covers.openlibrary.org/b/isbn/%7B%7B!!isbn%7D%7D-M.jpg>]]
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

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/b8d2d9c6-a05c-4771-9e71-2365140c1a32n%40googlegroups.com.

Reply via email to