editFieldPlugin(?) problem

62 views
Skip to first unread message

Reto

unread,
Nov 18, 2012, 6:39:19 AM11/18/12
to tiddl...@googlegroups.com
I have a template tiddler WorkHeader containing an <<edit [FIELDNAME]>>.

I get the text of this template tiddler in an other tiddler by script:

<script>return store.getTiddlerText("WorkHeader");</script>

Everything is fine: The macro is rendered, the field is found.

Then I wrote a plugin which basically is doing the same:

config.macros.showWorkHeader.handler = function showTitleOfField(place,macroName,params, wikifier, paramString) {
   returnValue = store.getTiddlerText("WorkHeader");
   wikify(returnValue, place); 
 };

But obviously it _is_ not the same because I get an error as output: error in macro, cannot call method 'getAttribute' of undefined.

I checked the returned text using 'alert': looks ok to me.

Any hints?

Eric Shulman

unread,
Nov 18, 2012, 10:21:23 AM11/18/12
to TiddlyWiki
> config.macros.showWorkHeader.handler = function showTitleOfField(place,macroName,params, wikifier, paramString) {

> in macro, cannot call method 'getAttribute' of undefined.
>
> I checked the returned text using 'alert': looks ok to me.
>
> Any hints?

Your function declaration is a bit odd. The name of the function is
'handler'.... but you also declare 'showTitleOfField'. Try removing
that extra name:

config.macros.showWorkHeader.handler=function(...) {

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...
http://www.TiddlyTools.com/#Donations

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:
http://www.TiddlyTools.com/#Contact

Reto

unread,
Nov 18, 2012, 12:09:39 PM11/18/12
to tiddl...@googlegroups.com
Your function declaration is a bit odd.  The name of the function is
'handler'.... but you also declare 'showTitleOfField'.  Try removing
that extra name:
 
config.macros.showWorkHeader.handler=function(...) {

Thanks, Eric. This is may first plugin, I did read tiddlywork.org, the old wiki and of course checked existing plugins (from tiddlytools).

Corrected this ... but still the same error. I try to setup the situation on tiddlyspot ...

Eric Shulman

unread,
Nov 18, 2012, 12:45:36 PM11/18/12
to TiddlyWiki
> > Your function declaration is a bit odd.  The name of the function is
> > 'handler'.... but you also declare 'showTitleOfField'.  Try removing
> > that extra name:
> > config.macros.showWorkHeader.handler=function(...) {
> Corrected this ... but still the same error. I try to setup the situation
> on tiddlyspot ...

You also need to declare the 'showWorkHeader' *object* before you
define the 'handler' method:

config.macros.showWorkHeader={};
config.macros.showWorkHeader.handler = function (...) {
...
};

OR

config.macros.showWorkHeader={
handler: function (...) {
...
};
}

-e

Reto

unread,
Nov 29, 2012, 3:48:53 PM11/29/12
to tiddl...@googlegroups.com
You also need to declare the 'showWorkHeader' *object* before you
define the 'handler' method:

config.macros.showWorkHeader={};
config.macros.showWorkHeader.handler = function (...) {
   ...
};

This is also done ... sorry, didn't pasted the whole code.

Was finally able to put up a test case on tiddlyspot:

Eric Shulman

unread,
Nov 29, 2012, 11:29:24 PM11/29/12
to TiddlyWiki
> Was finally able to put up a test case on tiddlyspot:
> http://extendedbrain.tiddlyspot.com/

Test cases make it MUCH easier to provide help!

Here's the problem:

1) Your macro handler function incorrectly declares only 5 arguments
rather than 6, omitting the 'tiddler' argument:
function(place,macroName,params,wikifier,paramString,tiddler)

2) wikify() has *four* parameters:
wikify(content,place,highlight,tiddler)
where:
'content' is the wiki text to be rendered
'place' is the DOM element in which to render the output
'highlight' is a regular expression pattern (used to highlight
search terms)
'tiddler' is the current tiddler (i.e., the one in which the
macro is embedded)
For most simple uses of wikify(), you can omit the highlight and
tiddler parameters. However... if the content you are rendering
includes any macros that rely upon the current tiddler context (e.g.,
the <<edit fieldname>> macro that you have embedded in the
"WorkHeader" content), then the tiddler param is NEEDED in order to
resolve the fieldname reference properly.

Thus... to fix your problem:
A) add the "tiddler" param to the handler declaration
and
B) use wikify(text,place,null,tiddler) when rendering your macro's
output.

Reto

unread,
Nov 30, 2012, 3:57:55 AM11/30/12
to tiddl...@googlegroups.com
Thus... to fix your problem:
A) add the "tiddler" param to the handler declaration
  and
B) use wikify(text,place,null,tiddler) when rendering your macro's
output.

The error has gone ... many thanks for for your much valued explantions and help!

I allowed myself to test your donation functionality ... works ;-).

Cheers
Reto
Reply all
Reply to author
Forward
0 new messages