On Wednesday, December 25, 2019 at 5:32:03 PM UTC-8, The Islander wrote:
>
> For the life of me I can't figure out how to concatenate a regular string
> with the contents of a tiddler and a variable inside a macro.
>
> Let's say 'variable' = 35
> Stringstuff{{$:/link/to/tiddler!!text}}$variable$
> ends up with:
> Stringstuff{{$:/link/to/tiddler!!text}}35
> Any idea how to how to get the {{}} to evaluate? How do I concat these
> three things?
> Even more frustrating is that if I put {{$:/link/to/tiddler!!text}} by
> itself in the macro it will evaulate just fine.
> I'm also not able to put {{$:/link/to/tiddler!!text}} in its own macro and
> then:
> Stringstuff<<new_macro>>$variable$
> It just comes out as Stringstuff<<new_macro>>35
>
Despite their appearance, TW macros aren't functions. That is, they don't
"evaluate and return".
They are more "text expanders". The only thing a macro does is to replace
$param$ with the value passed to it,
and replace $(variable)$ with the value of the variable (only if it was
defined *outside* the macro).
It is up to the "caller" of the macro to determine how it is rendered, if
at all. If the macro is invoked from wiki content,
then it is rendered, as if it had been typed right there; but, if the macro
result is used as a parameter values for a widget
calls, then it is not parsed, and it left up to the widget itself to use,
as is.
So, for your purposes, to combine literal text and the contents of a
tiddler, you could write something like this:
\define combined()
Stringstuff$(tiddlerstuff)$$variablestuff$
\end
and then invoke it like this:
<$vars tiddlerstuff={{$:/link/to/tiddler!!text}}>
<<combined 35>>
</$vars>
The enclosing $vars widget retrieves the value from the tiddler contents
The scope of the variable is only within the enclosing <$vars>...</$vars>
section
For the use-case you mentioned in your OP, something like this might do:
\define makeurl()
http://myIframeRequest.html?param1=$(value1)$¶m2=$(value2)$
\end
<$edit-text field="value1" />
<$edit-text field="value2" />
<$vars value1={{!!value1}} value2={{!!value2}}>
URL src is: <<makeurl>><br>
<iframe src=<<makeurl>> />
</$vars>
Of course, you could put the edit-text widgets into a separate tiddler
(e.g., Tiddler2)
and then reference them in the $vars, using {{Tiddler2!!value1}} and
{{Tiddler2!!value2}}
Hopefully, the above explanation is enough to get you started in the right
direction...
Let me know how it goes.
enjoy,
-e
Eric Shulman
InsideTiddlyWiki - http://www.TiddlyTools.com/InsideTW
--
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/6cf875ba-703e-4ec9-b300-324b70b8c68f%40googlegroups.com.