
|
|
|
Pagenews website
|
|
|
|
|
|
|
|
|
|
|
|
Pagenews website
Copyright (C) 2004,2005,2006
by Philipp Kindt
|
|
Writing code for Donparser
Content
Writing code for Donparser
Hello world in Donparser
Further resources
Hello world in Donparser
Now you know how a donparser template looks like. This is enough for writing templates! But if you want to develope your
own perl code that interacts with donparser, you need to know the donparser API.
It is quite easy.
If you have the codehandler [CODE mycode], the perl file mycode.pl in cgi-bin/restricted/codehandlers is executed.
After that, all functions of this file are accessible.
If you call a function by a function handler, the function gets the donparser object of the donparser which parses the template containing the handler as its first param,
the params following are the ones given along with the function handler.
The functions (or the code directly) can add simple replacement handlers to the donparser objects.
Hello world in donparser
This example will show you how the code and the template work together.
It defines a function which returns "hello world in donparser!" and adds a simple replacement handler having the value "hi again!"
to the calling template. Copy'n paste theese two files! and save them in their locations to try!
File: helloworld.dontemplate (place it in cgi-bin/restricted/templates/user)
[REMARK this is the header of the template. actually, in most cases it does not really matter if you use a header or not]
[REMARK first, let's load the code we need. We load helloworld.pl in cgi-bin/restricted/codehandlers]
[CODE helloworld]
<html>
<body>
This is my donparser hello world template:<br>
[REMARK call the function and place the return value in the template]<br>
[RFUNCTION helloworld::rf_say_hello "hi again"]<br>
<br>
[REMARK and now we call the simpple replacement handler]<br>
[MYHANDLERNAME]<br>
</body>
</html>
|
File: helloworld.pl (place it in cgi-bin/restricted/codehandlers)
#give your file a package name
package helloworld;
sub rf_say_hello{
#first, we have to get the donparser object:
my $parser = $_[0];
#lets add a handler to the parser that has the value of the first param given by the RFUNCTION-handler:
$parser->add_handler("MYHANDLERNAME", $_[1]);
#and we give a return value
return "hello world in donparser!";
}
|
Now you can open news.cgi?do=helloworld in your browser!
You should see
This is my donparser hello world template:
hello world in donparser!
hi again
|
Further resources
To get further information about writing code for donparser, use the following resources:
- Donparser documentation
- The source code: see the files in cgi-bin/include/donlibs/donparser_parts, especially donparser_part_api.pm
and donparser_part_parse.pm
- Contact the author at the Pagenews website www.pagenews.dd.vu
|
->
admin log-in
Powered by Pagenews DN 6.1.2 by Philipp Kindt
|