Passing tiddler field as parameter in macro shorthand

Newbie here. I have a macro embedyoutubevideo. My tiddler has a field youtube with value K3jy1HFtwR4.

Could someone explain why this does not work, and how I can fix it:
<<embedyoutubevideo {{!!youtube}}>>

However the following invocations do work:
<$macrocall $name=“embedyoutubevideo” link={{!!youtube}}>

<<embedyoutubevideo K3jy1HFtwR4>>

I’d prefer to use the shorthand notation if possible.

The shorthand macro syntax only permits literal parameter values (enclosed in single-quotes, double-quotes, tripled double quotes, or doubled-square brackets) with optional parameter names (e.g., link:"K3jy1HFtwR4"), and does not support transclusions (the {{...}} syntax) as noted in the documentation. For transcluded parameter values, you need to use the $macrocall widget syntax.

https://tiddlywiki.com/#Macro%20Calls%20in%20WikiText

3 Likes

Another approach is to pass a simple string, the name of the field, “youtube” and inside the macro retrieve this value,

\define embedyoutubevideo(fieldname) 
... {{!!$fieldname$}} {{{ [all[current]get[$fieldname$]] }}} etc...
\end
<<embedyoutubevideo youtube>>

however in the example you give the macros is called “embedyoutubevideo” why not just default the macro to using the youtube?

More often than not, I prefer short-hand transclusion to macros.

Here’s how I handle what you’re trying to do:

I create a transclusion template tiddler called “YouTube” with the following content:

<iframe width="560" height="315" src={{!!title}} title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

Take note of src={{!!title}}

Here are two examples of how I use this …

A direct link entered in the text of a tiddler:

{{ https://www.youtube.com/embed/ocFPTl14wtA || YouTube}}

A link retrieved from the field of some tiddler:

{{{ [{Some Tiddler!!youtube}] || YouTube }}}

“Some Tiddler” has a field called “youtube” with the value: https://www.youtube.com/embed/ocFPTl14wtA

You might want to consider putting the common part of URL’s in the template tiddler, and then only refer to the unique parts elsewhere.

So, alternatively: (I prefer this approach)

I create a transclusion template tiddler called “YouTube” with the following content:

<iframe width="560" height="315" src={{{ [<currentTiddler>addprefix[https://www.youtube.com/embed/]] }}} title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

Take note of src={{{ [<currentTiddler>addprefix[https://www.youtube.com/embed/]] }}}

Here are two examples of how I use this …

A direct link entered in the text of a tiddler:

{{ ocFPTl14wtA || YouTube}}

A link retrieved from the field of some tiddler:

{{{ [{Some Tiddler!!youtube}] || YouTube }}}

“Some Tiddler” has a field called “youtube” with the value: ocFPTl14wtA

5 Likes