The return value of handle() is $data in the render() parameters.handle() is only executed rarely, pretty much only when the page is edited. render() is executed much more often and most often will use the saved results from handle().
I noticed your substr() call in handle uses 10 for '{{' when the pattern uses '<' and so should be 9.
Cheers, Chris Tony Steward wrote:
Hello, I am trying to understand how plugin works & have adjusted the sample in the tutorial. How do I get data from the handle into render? I want to put the likes of <KEYCONV|red> into a wiki page and have it return "Hello Worldred" Below is what i tried and failed. Please show me how to do this. Thanks Tony <?php /** * Plugin Skeleton: Displays "Hello World!" * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Christopher Smith <chris@xxxxxxxxxxxxx> */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_keyconv extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Tony Steward', 'email' => 'tony_steward@xxxxxxxxx', 'date' => '2007-05-29', 'name' => 'Key Converter', 'desc' => 'Show keys from differant manufacturers', 'url' => 'http://www.locks.stewardclan.net/lockswiki/', ); } /** * What kind of syntax are we? */ function getType(){ return 'substition'; } /** * What kind of syntax do we allow (optional) */ // function getAllowedTypes() { // return array(); // } /** * What about paragraphs? (optional) */ // function getPType(){ // return 'normal'; // } /** * Where to sort in? */ function getSort(){ return 999; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('<KEYCONV|.+?>',$mode,'plugin_keyconv'); // $this->Lexer->addEntryPattern('<keyconv>',$mode,'plugin_keyconv'); } // function postConnect() { // $this->Lexer->addExitPattern('</keyconv>','plugin_keyconv'); // } /** * Handle the match */ function handle($match, $state, $pos, &$handler){ $match = substr($match, 10, -2); // strip {{keyconv> from start and }} from end switch ($state) { case DOKU_LEXER_ENTER : break; case DOKU_LEXER_MATCHED : //return array($state, $match); break; case DOKU_LEXER_UNMATCHED : break; case DOKU_LEXER_EXIT : break; case DOKU_LEXER_SPECIAL : break; } return array($match); } /** * Create output */ function render($mode, &$renderer, $data) { if($mode == 'xhtml'){ $renderer->doc .= "Hello World!"; // ptype = 'normal' $renderer->doc .= $data; // $renderer->doc .= "<p>Hello World!</p>"; // ptype = 'block' return true; } return false; } }
-- DokuWiki mailing list - more info at http://wiki.splitbrain.org/wiki:mailinglist