[TW5] How to read/set tiddler field value from macro?

2,046 views
Skip to first unread message

Дмитрий Ивашкин

unread,
Apr 23, 2014, 9:56:45 AM4/23/14
to tiddl...@googlegroups.com
I have a tiddler with a custom field in it, and would like to be able to set its value from macro. Macro will be called everytime some other field of the same tiddler changes.
Is there a way to achieve that?

Dmitry Ivashkin

unread,
Apr 23, 2014, 10:03:13 AM4/23/14
to tiddl...@googlegroups.com
Also, where can I find documentation about methods and properties of "this" object in javascript macros?

I came across calls like this:

this
.getVariable("currentTiddler")

but couldn't find any sort of documentation. Same for story object, etc.


--
Best regards,
Dmitry Ivashkin


On Wed, Apr 23, 2014 at 3:56 PM, Дмитрий Ивашкин <dmitry....@gmail.com> wrote:
I have a tiddler with a custom field in it, and would like to be able to set its value from macro. Macro will be called everytime some other field of the same tiddler changes.
Is there a way to achieve that?

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/jeP2-qlpdrk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.

Jeremy Ruston

unread,
Apr 24, 2014, 6:08:44 AM4/24/14
to TiddlyWiki
Hi Dmitry

On Wed, Apr 23, 2014 at 3:03 PM, Dmitry Ivashkin <dmitry....@gmail.com> wrote:
Also, where can I find documentation about methods and properties of "this" object in javascript macros?

The "this" object in a JavaScript macro points to the containing widget instance in the render tree. So that means it has the methods described in widget.js:

 

this
.getVariable("currentTiddler")

but couldn't find any sort of documentation.

There is some documentation in the source code for widget.js.
 
Same for story object, etc.

There isn't really a "story" object in TW5 in the same way as TWC.
 
I have a tiddler with a custom field in it, and would like to be able to set its value from macro. Macro will be called everytime some other field of the same tiddler changes

Is there a way to achieve that?

Macros are just used to return a chunk of wikitext for further processing. They should not make modifications to tiddlers in the wiki store. The reason is that you can't control when the macro is called; it may be called repeatedly as part of refresh processing. So it's important that macros do not have any other side effects beyond generating their text.

I've updated the docs a little to reflect the points you've raised:


Best wishes

Jeremy
 

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/jeP2-qlpdrk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.

--
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 tiddlywiki+...@googlegroups.com.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

Dmitry Ivashkin

unread,
Apr 24, 2014, 7:05:06 AM4/24/14
to tiddl...@googlegroups.com
Thank you Jeremy! This is helpful.

What I'm struggling with is inability to use the result of a macro as a parameter for a filter, or a value of a variable or a field in the current tiddler. Basically, what I wanna do is a tiddler that shows a list of all tiddlers that were created on a given date (that is chosen by $edit-text widget - but it is in wrong format, so I'm using macro to convert one date string to another).

--
Best regards,
Dmitry Ivashkin


Jeremy Ruston

unread,
Apr 24, 2014, 7:12:15 AM4/24/14
to TiddlyWiki
Hi Dmitry

What I'm struggling with is inability to use the result of a macro as a parameter for a filter, or a value of a variable or a field in the current tiddler. Basically, what I wanna do is a tiddler that shows a list of all tiddlers that were created on a given date (that is chosen by $edit-text widget - but it is in wrong format, so I'm using macro to convert one date string to another).

The trick that you can often use is to compose the elements of the filter through a macro definition. For example:

\define myFilter()
[is[current]tag[$(param)$]]
\end

<$set name="param" value={{!!myfield}}>

<$list filter=<<myFilter>> template="myTemplate"/>

</$set>

Does that help?

Best wishes

Jeremy



Dmitry Ivashkin

unread,
Apr 24, 2014, 7:34:34 AM4/24/14
to tiddl...@googlegroups.com
Hi Jeremy, 

Unfortunately, it doesn't seem to help.

The trick that you can often use is to compose the elements of the filter through a macro definition. For example:

\define myFilter()
[is[current]tag[$(param)$]]
\end

<$set name="param" value={{!!myfield}}>

<$list filter=<<myFilter>> template="myTemplate"/>

</$set>

In your example, $(param)$ value will still be equal to that of myfield, right? I still can't see how to make param to be equal to what my macro returns. That is, I can print the result of the macro by adding <$macrocall name="mymacro" value={{!!myfield}}> to my tiddler, that's fine. However, I can't make $(param)$ to be equal to that string.

\define myFilter()
<$macrocall name="mymacro" value=$(param)$>
\end

doesn't work either.

--
Regards, Dmitry.

Jeremy Ruston

unread,
Apr 24, 2014, 12:11:55 PM4/24/14
to TiddlyWiki
Hi Dmitry

In your example, $(param)$ value will still be equal to that of myfield, right? I still can't see how to make param to be equal to what my macro returns. That is, I can print the result of the macro by adding <$macrocall name="mymacro" value={{!!myfield}}> to my tiddler, that's fine. However, I can't make $(param)$ to be equal to that string.

Ah, I see what you mean. Yes, we need a way to use a macro invocation as the operand of a filter operator. For example, this would match tiddlers carrying the tag returned by <<myMacro param>>:

[tag<myMacro param>]

Such a syntax would match the existing [tag{title!!field}] syntax.

I've added a ticket:


Best wishes

Jeremy




 
 

\define myFilter()
<$macrocall name="mymacro" value=$(param)$>
\end

doesn't work either.

--
Regards, Dmitry.

--
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 tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages