plugin:function
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
plugin:function [2012-12-24 04:58] – Clarify example tom_c | plugin:function [2014-12-19 14:29] – 2001:660:4701:2010:76d0:2bff:fe2a:8bbf | ||
---|---|---|---|
Line 6: | Line 6: | ||
email : tcafferty@glocalfocal.com | email : tcafferty@glocalfocal.com | ||
type : syntax | type : syntax | ||
- | lastupdate : 2012-11-09 | + | lastupdate : 2013-06-08 |
- | compatible : Angua | + | compatible : Angua, Binky, Hrun |
depends | depends | ||
conflicts | conflicts | ||
Line 29: | Line 29: | ||
===== Examples/ | ===== Examples/ | ||
- | A sample | + | Two sample |
- | < | + | < |
- | The example passes 4 parameters to the invoked function. | + | < |
+ | < | ||
+ | < | ||
+ | </ | ||
+ | The example passes 4 parameters to the invoked function, invokes a different function with no parameters, and then calls the first function again. | ||
- | Parameters are passed as strings. The example shows how the invoked function typecasts the last parameter to be used as an integer. | + | Parameters are passed as array elements. The example shows how the invoked function typecasts the last parameter to be used as an integer. |
Parameters are not required. The simplest usage is to invoke a function with no parameters. | Parameters are not required. The simplest usage is to invoke a function with no parameters. | ||
+ | |||
+ | Examples can be seen at [[http:// | ||
===== Syntax ===== | ===== Syntax ===== | ||
Line 47: | Line 53: | ||
===== Configuration and Settings ===== | ===== Configuration and Settings ===== | ||
- | - Add a file containing the php function into the /functions folder. The main function must be called | + | - Add a file containing the php function into the /functions folder. The main function must be called |
+ | < | ||
+ | | ||
+ | }; | ||
+ | </ | ||
- Add a configuration parameter in / | - Add a configuration parameter in / | ||
- You can add a function description in / | - You can add a function description in / | ||
Line 55: | Line 65: | ||
=== Change Log === | === Change Log === | ||
- | {{rss>http:// | + | {{rss>https:// |
=== Known Bugs and Issues === | === Known Bugs and Issues === | ||
Line 79: | Line 89: | ||
Best regards | Best regards | ||
-- [[user> | -- [[user> | ||
+ | |||
+ | I noticed a problem when I was using two different functions on a single page. The run() declaration was already defined when it hit the second function call. I was able to solve this by using variable function declarations. Here is the updated render function in syntax.php and the function declaration in the example helloworld.php | ||
+ | <code syntax.php> | ||
+ | function render($mode, | ||
+ | global $conf; | ||
+ | if($mode == ' | ||
+ | list($state, | ||
+ | |||
+ | switch ($state) { | ||
+ | case DOKU_LEXER_SPECIAL : | ||
+ | preg_match("# | ||
+ | $func = $matches[1]; | ||
+ | $a = explode('?', | ||
+ | $func = $a[0]; | ||
+ | if (!empty($a[1])) { parse_str($a[1], | ||
+ | else { $params = ''; | ||
+ | if(preg_match("# | ||
+ | $renderer-> | ||
+ | $filename = DOKU_PLUGIN . ' | ||
+ | include ($filename); | ||
+ | $renderer-> | ||
+ | } | ||
+ | else | ||
+ | $renderer-> | ||
+ | break; | ||
+ | | ||
+ | } | ||
+ | return true; | ||
+ | } | ||
+ | | ||
+ | // unsupported $mode | ||
+ | return false; | ||
+ | } | ||
+ | </ | ||
+ | <code helloworld.php> | ||
+ | $thisfunction = function($params) { | ||
+ | // Create output data | ||
+ | $dataout='< | ||
+ | |||
+ | $num=(int)$params[' | ||
+ | $dataout .= ' The ' | ||
+ | foreach ($params AS $key=> | ||
+ | if ($val != $num) $dataout.=$val.'< | ||
+ | } | ||
+ | return $dataout; | ||
+ | }; | ||
+ | </ | ||
+ | Using a variable to hold the function allows it to be overwritten for each function declaration. | ||
+ | -- [[user> | ||
+ | |||
+ | Millsdude, thanks for this update! It works real nice. I incorporated it into the release. | ||
+ | -- [[user> | ||
+ | |||
+ | It may be worth noting that, although DokuWiki itself [[: |
plugin/function.txt · Last modified: 2018-05-31 00:16 by Klap-in