Putting it all together

Parsing the Template

Use the parseTemplate() method from the text-parser class to replace shortcodes with their real value.
$tp->parseTemplate('template','use-core-shortcodes','shortcode-class');

Basic Example

$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.

Full Example with loop

$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.










Thursday 30 May 2013 - 17:00:00 admin,

Social Links