Plugin template TODO
Textpattern plugins are perhaps best thought of as functions supplementary to those found in Textpattern core.
Functions residing in this file respond to
<txp:foo /> and
<txp:foo>bar</txp:foo> tags found in Page templates, Form templates, @@Articles@@ and other dynamic content containers in Textpattern. A Textpattern plugin template is available on GitHub for plugin distribution.
On this page:
Template package contents
In addition to the LICENSE and README files, the plugin template contains the following:
- zem_tpl.php - Contains the code to compile plugins into the format required by the Textpattern plugin installer.
- zem_plugin.php - Is the template itself. Make a copy of this file and edit it to write your plugin.
- zem_example.php - Is an example plugin that demonstrates both public-side tags and admin-side user interface features.
Typical template use
Typical commands (via command-line) that you’ll probably use:
$ cp zem_plugin.php abc_myplugin.php [edit abc_myplugin.php] $ php abc_myplugin.php > abc_myplugin-0.1.txt
abc_myplugin-0.1.txt is the finished plugin, ready to install.
Important and helpful notes:
- Whatever is returned by the plugin function will be output by the
- Plugin functions have access to all the functions available to publish.php, including everything in textpattern/lib. (Further reference on these resources is forthcoming.)
- If you would like to pass variables to the plugin function(s) via
paramaters in the
<txp:plugin_name />tag, these will be passed as the first argument to the function as an associative array (
$varname => $value).
- If you would like to pass a variable to the plugin function by
enclosing it in
<txp:foo>bar</txp:foo>, this will be passed as the second argument to the function as a string.
- Do not use
<?php ?>tags within the plugin source.
It speeds up development tremendously if you do the following:
- Make sure plugin name and plugin filename correspond; e.g. zem_test should be in zem_test.php.
- Create a directory, /full/path/dev/plugins.
- Drop your uncompiled plugins in that directory. Do not put zem_tpl.php in the same directory.
- In the Advanced preferences panel of the admin-side, set plugin cache directory to /full/path/dev/plugins.
Now during development you can skip the compile, upload, activate steps (and you’re not confined to editing in the admin panel or copy/paste). Simply edit the file in the tmp dir, it will be included on each run.