Hi cpaussa
On Wed, Aug 27, 2014 at 8:25 PM, cpaussa via TiddlyWiki <
[email protected]> wrote:
> This post has two mysteries for me
>
> 1. I can't pass the results from a macrocall to a javascript macro into
> the set value in the <$button> widget
> The macro call returns true rather than the macro result no matter what I
> do.
>
> 2. The variables that I set using the <$set> widget don't act in the same
> way that the global variables like $(storyTiddler)$ and $(currentTiddler)$
> act
> This works
> =========
> <$button set="$(storyTiddler)$!!done" setTo=<<addThis>> > text </$button>
> [[$(currentTiddler)$ ]]
> This doesn't
> =========
> <$set name="old" value="test">
> <$button set="$(storyTiddler)$!!done" setTo=<<addThis>> > text </$button>
> [[$(old)$]]
> </$set>
>
The problem with the second example is basically that variable substutions
like $(old)$ are applied before the macro is executed. That means that the
value of the variable "old" that gets substituted is the one that was in
force at the point that the macro was invoked. By the time your <$set>
widget is executed the macro content will have already been substituted.
The solution is to use an inner macro:
\define inner()
<$button set="$(storyTiddler)$!!done" setTo=<<addThis>> > text </$button>
[[$(old)$]]
\end
\define outer()
<$set name="old" value="test">
<<inner>>
</$set>
\end
Hope that helps,
Best wishes
Jeremy
>
> Here's the scenario:
>
> I have a macro that removes one string from another
> ====================================================
>
> exports.run = function(origstring, removestring) {
> return origstring.replace(removestring,"");
> };
>
>
> I have a tiddler with fields
> ====================
> title:test
> todos: one two three
> done: one two
> text:
> * {{one||templatename}}
> * {{two||templatename}}
> * {{three||templatename}}
>
> I have a template that creates a button for each value in the [todos -
> done] and done fields
> ====================================================
> title: templatename
> text:
> \define addThis() $(new)$ $(old)$
>
> \define makebutton()
>
> <$list filter="[title[$(storyTiddler)$]field:todos/$(currentTiddler)$/]">
> <$tiddler tiddler="$(currentTiddler)$" >
> <$list
> filter="[title[$(storyTiddler)$]!field:done/$(currentTiddler)$/]">
> <$set name="old" value={{$(storyTiddler)$!!done}}>
> <$set name="new" value="$(currentTiddler)$">
> <$button set="$(storyTiddler)$!!done" setTo=<<addThis>>
> >O</$button> [[$(currentTiddler)$ ]]
> </$set>
> </$set>
> </$list>
> </$tiddler>
> </$list>
>
> <$list filter="[title[$(storyTiddler)$]field:done/$(currentTiddler)$/]">
> <$set name="old" value={{$(storyTiddler)$!!done}}>
> <$set name="new" value="Test" >
> <$tiddler tiddler="$(currentTiddler)$" >
> <$button set="$(storyTiddler)$!!done" setTo=<$macrocall
> $name="removestring " origstring = "$(old)$" removestring = "$(new)$" /> >
> ~~ $(currentTiddler)$ ~~ </$button>
> <!-- This is where the error is
> The macro call sets the field to true rather than to $(old
> ).replace($(new)$,"")
> -->
> </$tiddler>
> </$set>
> </$set>
> </$list>
> \end
>
> <$macrocall $name="makebutton" />
>
> --
> 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 post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/tiddlywiki.
> For more options, visit https://groups.google.com/d/optout.
>
--
Jeremy Ruston
mailto:[email protected]
--
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 post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.