parseTemplate()
function.{MY_SHORTCODE}
sc_
. eg. sc_my_shortcode()
. This means that {MY_SHORTCODE}
is replaced by what is returned by sc_my_shortcode()
.{MY_SHORTCODE: x=foo&y=bar}
Create a folder called templates
inside your plugin directory, and inside create an empty file using the name of your plugin folder, followed by _template.php
. eg. myplugin_template.php
Inside this file add an array by the same name, but in UPPERCASE: eg. $MYPLUGIN_TEMPLATE['xxxx']
xxxx
can be anything you want, but we suggest using start
, item
, end
etc. when applicable. This value should always be lowercase. Here's a simple example of the contents of myplugin_template.php
:
<?php
$MYPLUGIN_TEMPLATE['start'] = "<ul>";
$MYPLUGIN_TEMPLATE['item'] = "<li>{MYPLUGIN_ITEM}</li>";
$MYPLUGIN_TEMPLATE['end'] = "</ul>";
?>
If your plugin will use several different types of templates, eg. a listing page and an input form. You can do something like this:
<?php
$MYPLUGIN_TEMPLATE['list']['start'] = "<ul>";
$MYPLUGIN_TEMPLATE['list']['item'] = "<li>{MYPLUGIN_ITEM}</li>";
$MYPLUGIN_TEMPLATE['list']['end'] = "</ul>";
$MYPLUGIN_TEMPLATE['form']['start'] = "<form>";
$MYPLUGIN_TEMPLATE['form']['body'] = "<div>{MYPLUGIN_FORMINPUT}</divi>";
$MYPLUGIN_TEMPLATE['form']['end'] = "</form>";
?>
$template = e107::getTemplate('myplugin'); // loads e107_plugins/myplugin/templates/myplugin_template.php
$template
array for parsing. $text = e107::getParser()->parseTemplate($template['start'], true, $scObj); // or $text = e107::getParser()->parseTemplate($template['form']['start'], true, $scObj);
myplugin_shortcodes.php
where myplugin
is the name of your plugin's folder. myplugin
with the name of your plugin's folder. class myplugin_shortcodes extends e_shortcode { // Enter Shortcode methods here }
sc_
prefix and what follows in lower case. {SAY_HELLO}
which will say 'hello' to the logged in user. class myplugin_shortcodes extends e_shortcode { function sc_say_hello($parm='') { return "Hello ".USERNAME; } }
{SAY_HELLO: name=john}
class myplugin_shortcodes extends e_shortcode { function sc_say_hello($parm) { return "Hello ".vartrue($parm['name']); } }
$sc->setVars($row);
in example below. class myplugin_shortcodes extends e_shortcode { function sc_say_hello($parm) { return "Hello ".vartrue($this->var['name']); } }
$sc = e107::getScBatch('myplugin',TRUE); // loads e107_plugins/myplugin/myplugin_shortcodes.php
$tp->parseTemplate('template','use-core-shortcodes','shortcode-class');
$template = e107::getTemplate('myplugin', 'form'); // load the 'form' template from the plugin folder. $tp = e107::getParser(); // get Parser Class. $sc = e107::getScBatch('myplugin',true); // get myplugin shortcodes from plugin folder. echo $tp->parseTemplate($template['start'], true, $sc); // parse the 'start' part of the 'form' template.
$sql = e107::getDb(); // get the database Class. $tp = e107::getParser(); // get Parser Class. $sc = e107::getScBatch('myplugin',true); // get myplugin shortcodes from plugin folder. $template = e107::getTemplate('myplugin', 'list'); // get template array of 'list' from plugin folder. echo $tp->parseTemplate($template['start'], true, $sc); // parse the 'start' part of the 'list' template. $rowArray = $sql->retrieve("SELECT field FROM #myplugin", true); // load the values from the plugin's database table. foreach($rowArray as $row) // loop through the database results. { $sc->setVars($row); // send the value of the $row to the class. echo $tp->parseTemplate($template['item'], false, $sc); // parse the 'item' } echo $tp->parseTemplate($template['end'], false, $sc); // parse the 'end' part of the 'list' template.