vpl,

First of all, the syntax for incorporating a variable into a filter 
expression is not <<variable>> but <variable>:

\define test_project()     {{{ [<my_tiddler>get[projectId]] }}}

However, this still may not work, depending on how you use the macro. It's 
tempting to think of macro transclusions as "function calls", where when 
you say <<test_project>> you get the result of evaluating their contents as 
wikitext. But this is not how macros work – instead, *the exact text of the 
macro* (with any $text substitutions$ the macro might include) is inserted 
wherever the <<macro transclusion>> is used, which in this case is a filter 
expression in triple curly braces.

Now, this will still work fine if you just say, for instance:

<<test_project>>

In this case, TW replaces <<test_project>> with {{{ 
[<my_tiddler>get[projectId]] }}}, then sees that wikitext in the body of a 
tiddler, evaluates it, and gets the project ID. But it won't work if you 
try to use it within another filter expression, or as the value of an HTML 
or widget attribute, e.g., suppose you had a tiddler whose title was this 
project ID and wanted to transclude it:

<$transclude tiddler=<<test_project>>/>

In this case, TW will be looking for a tiddler called "{{{ 
[<my_tiddler>get[projectId]] }}}", and it presumably won't find it.

If you need to, you can get around this with the $wikify widget:

<$wikify name="myProjectId" text=<<test_project>>>
  <$transclude tiddler="myProjectId"/>
</$wikify>

In this case, you explicitly tell TW to evaluate the wikitext "{{{ 
[<my_tiddler>get[projectId]] }}}", then use the result to transclude the 
appropriate tiddler.

You can read more on this in the Wikification section 
<https://groktiddlywiki.com/read/#Wikification> of *Grok TiddlyWiki*.
On Tuesday, August 17, 2021 at 9:56:51 AM UTC-5 vpl wrote:

> Hi,
>
> I want to define a global variable in my script with the value contained 
> into a tiddler field
> When I hard code the global variable like
>
> \define test_project()     project-1
>
> I can use the <<test_project>> variable without issue 
>
> But when I want this <<test_project>> to be initialised to a tiddler's  
> field like the following this does not work
>
> \define test_project()     {{{ [<<my_tiddler>>get[projectId]] }}}
>
> Any "magic" idea ..??
>
> Thanks a lot for your support
>
> Regards vpl
>

-- 
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/0cdcb9ac-2f0a-4f50-a6a8-fd9dfac7819cn%40googlegroups.com.

Reply via email to