pass variable to macro via macrocall not working

91 views
Skip to first unread message

Dave Parker

unread,
Jul 2, 2020, 1:06:13 AM7/2/20
to TiddlyWiki
Here I've tried several different ways to get a variable into Tobibeer's Sparkl plugin (a TW5 version of the old TWC sparklines tiny graph thing)


Here's several attempts:
\define sprk2(val)
<$sparkl values="$val$"/> $val$ :: <$sparkl values="13 7 19 15"/>
\end

\define sprk()
<$macrocall $name=sprk2 val="{{||vasSumGraph}}"/>
\end

..<<sprk>>..

1) {{||vasSumGraph}} 

2) <<sparkl "{{||vasSumGraph}}">> 

3) <<sparkl "13 7 19 15">>

4) <$sparkl values="{{||vasSumGraph}}"/>

5) <$sparkl values="13 7 19 15"/>

with the following results:


You can see in the top one the $val$ successfully passes the info, and when the real info is entered in to the widget directly that works too, but when you put the $val$ into the widget it fails.

I've looked for similar questions and suspect I have to maybe use "<$set" somehow, but can't seem to figure it out.

Any suggestions?


Thanks,
- Dave

TW Tones

unread,
Jul 2, 2020, 2:23:13 AM7/2/20
to TiddlyWiki
Dave,

First thing I notice is 
val="{{||vasSumGraph}}"

The contents will be passed as a literal string. Use this instead.
val={{||vasSumGraph}}

When using macros or transclusions the delimiters they use such as `<<` and `{{` doubles as a way to delimit themselves. 
Additional delimiters just say you are passing a literal.

If in doubt calling any macro including your own, use the macrocall widget
<$macrocall $name=sparkl varname={{||vasSumGraph}}/>
I do not see the macro sparkl defined so I guessed varname
Note the use of $name this keeps the possibility of using a "name" parameter in the macrocall.

Macrocall lets you pass parameters from various macros and transclusions including fields, tiddlers text references even from something constructed with triple curly braces.
{{{[all[current]addprefix[$:/namespace/]]}}

The short form of macrocall is basically limited to the following
<<macroname "firstparamvalue" namedparam:"Value for named param">>


Although inside a macro you can use $(varname)$ and $parmname$
So one macro calling another can say
<<macroname "$firstparam$" namedparam:"$namedparam$" 3rd-param:"$(currentTiddler)$">>

I hope this quick briefing helps. It is all documented but takes time to bring this together in ones head.

Regards
TW Tones

Dave Parker

unread,
Jul 2, 2020, 12:44:19 PM7/2/20
to TiddlyWiki
Thank you for looking at this Tony,

when I take out the quotes,
Enter code here..\define sprk2(val)

<$sparkl values="$val$"/> $val$ :: <$sparkl values="13 7 19 15"/>
\end

\define sprk()
<$macrocall $name=sprk2 val={{||vasSumGraph}}/>
\end

..<<sprk>>...


here's what happens

As you can see, now the part that simply passes the text  $val$ disappears, so that's why I thought the quotes were required.

I've also tried taking out the quotes further up (for the widget) like this:
\define sprk2(val)
<$sparkl values=$val$/> $val$ :: <$sparkl values="13 7 19 15"/>

\end

\define sprk()
<$macrocall $name=sprk2 val="{{||vasSumGraph}}"/>
\end

and I end up with this:
i.e. the little graph thing (again) just disappears (compared with the original picture in the first post)

Mat

unread,
Jul 2, 2020, 1:02:06 PM7/2/20
to TiddlyWiki
Try

\define sprk2(val) <$sparkl values={{{ [enlist[$val$]] }}} />
 
<:-)

Dave Parker

unread,
Jul 2, 2020, 1:29:48 PM7/2/20
to TiddlyWiki
Oh, yes Eric showed me that the other day on a different thread. (Got to get my different brain cells to talk to one another)

Thank you!, I'll try that out later today

Dave Parker

unread,
Jul 2, 2020, 9:00:23 PM7/2/20
to TiddlyWiki
That didn't work :'(


I think I'm getting closer though:

if you go to here:

and in [[New Tiddler]] paste this in
..<$set name="val" value={{||New Tiddler 1}}>
<$sparkl values=<<val>>/>
</$set>
..

..<$set name="val" value={{!!foo}}>
<$sparkl values=<<val>>/>
</$set>
..

----

{{||New Tiddler 1}}

make a field "foo" with "1 2 3 4"

then in "New Tiddler 1" paste in
{{!!foo}}

and add field "foo" with "4 3 2 1"

You'll see the direct field transclusion works, but not the {{||tiddler}} one.  There must be something about that kind of transclusion that requires special handling





TW Tones

unread,
Jul 2, 2020, 10:52:59 PM7/2/20
to TiddlyWiki
Dave,

  • You use value={{||New Tiddler 1}}
  • This is uncommon, I think you want the value to equal the content of New Tiddler 1 ?
  • Use this without the "||" {{New Tiddler 1}} the default field is text
  • you could equally say {{New Tiddler 1!!text}} or any other fieldname, but text is default
  • The other use is often called a template
    • {{||New Tiddler 1}} means transclude the contents of "New Tiddler 1" with here the currentTiddler here.
    • {{othertiddler||New Tiddler 1}} means transclude the contents of "New Tiddler 1" with "othertiddler" the currentTiddler.
The bold item is possible you answer, or a start the rest background knowledge I recommend learning.

I do not have the setup to fully test you solution.

Regards
Tony

Mark S.

unread,
Jul 3, 2020, 12:16:07 AM7/3/20
to TiddlyWiki
We don't know what's in vasSumGraph (or New Tiddler 1 in your other example), so it's hard to comment.
I can only speculate that vasSumGraph contains a process for generating a list of numbers. In which case you might
need to wikify it first,

<$wikify text={{||vasSumGraph}} name="nums">

<$sparkl values=<<nums>>/>

</$wikify>

I think we need to know a little more to be of service.

Good luck!

Dave Parker

unread,
Jul 3, 2020, 2:17:55 AM7/3/20
to TiddlyWiki
Tony - yes, I use the {{||tiddler}} format a lot as its very convenient for setting up a remote tiddler as a template to view the local tiddler's data, especially if the code to transform the data is quite big.  (in this case its quite simple)

Thank you Mark, wikify for the win!!

You can see it in action if you make 2 new tiddlers on the sparklines tiddlywiki 
then first make a new tiddler [[New Tiddler]], paste this in:
! wikify attempt,
!!! use remote template to transform local data
<$wikify text="{{||New Tiddler 1}}" name="nums">

*<$sparkl values=<<nums>>/>
*<$text text=<<nums>>/>
</$wikify>

----

! from this tiddler directly
<$set name="val" value={{!!foo}}>

*<$sparkl values=<<val>>/>
*<$text text=<<val>>/>
</$set>

----
! from remote tiddler directly

*transclude remote tiddler: {{New Tiddler 1}}
*sparklines via field, not template<$sparkl values={{New Tiddler 1!!foo}}>

and add a field "foo" with contents: "1 2 3 4"

then make another new tiddler [[New Tiddler 1]] and paste this in:
{{!!foo}}

and add the field "foo" with contents "4 5 2 1"

that results in this:



Reply all
Reply to author
Forward
0 new messages