TemplatePower
Explanation
TemplatePower() is outdated library for site templating, not available anymore.
e107 uses its own template system but it is too complex and it demands creating e107 shortcodes what could time consuming.
At this phase (after some attempt to use e107::getTemplate()) we decided only replace existing code with e107 simpleParser() that replaces shortcodes with variables without need e107 shortcodes files.
Get template file
For time being - creating e107 templates is advanted stuff, tons of arrays -
/* temp solution before e107 templating to replace TemplatePower solution */
public function getTpl($filename) {
$sitetheme = deftrue('USERTHEME', e107::getPref('sitetheme'));
$themepath = e_THEME.$sitetheme."/skins/";
/*
$defaultskin = e107::getSingleton('efiction_settings')->getPref('skin'); //will be removed ???
$skinpath = _BASEDIR."skins/".$defaultskin."/";
*/
$default = "efiction_tpls/"; //new folder used to see what left
$defaultpath = _BASEDIR.$default;
if(file_exists($themepath.$filename)) $tpl = file_get_contents($themepath.$filename) ;
else $tpl = file_get_contents($defaultpath.$filename) ;
return $tpl;
}
Example:
$reviewsblock_template = e107::getSingleton("efiction_core")->getTpl("reviewsblock.tpl");
Add variables
How to replace:
from this:
if(file_exists("$skindir/reviewblock.tpl")) $tpl->assignInclude("reviewsblock", "$skindir/reviewblock.tpl" ); else $tpl->assignInclude("reviewsblock", "default_tpls/reviewblock.tpl");
to:
$reviewsblock_template = e107::getSingleton("efiction_core")->getTpl("reviewsblock.tpl");
$reviewsblock_output = "";
It is just copy of $tpl->assign()
Example:
from:
$tpl->newBlock("reviewsblock")
to
$reviewsblock_vars = array();
From:
$tpl->assign("reviewer" , $reviewer );
to:
$reviewsblock_vars['reviewer'] = $reviewer;
This is just manual stuff.
TPL file
Actual tpl file
New tpl file were moved/copied to efiction_tpls folder
It depends on depth of tpl hierarchy if there is more files or not (change 1:1 agains defaults_tpl folder)
reviewsblock.tpl was copied 1:1
Next step:
change all keys to capitals
Example: reviewsblock.tpl:
<!-- START BLOCK : reviewsblock -->
<div class="listbox">
<div class="content{ODDEVEN}">
<span class="label">Reviewer: </span>{REVIEWER} <span class="label">{MEMBER}</span> {RATING} {REPORTTHIS}<br />
<span class="label">Date: </span>{REVIEWDATE}
<span class="label">Title: </span>{CHAPTER}
<p>{REVIEW}</p>
{ADMINOPTIONS}
</div>
</div>
<!-- END BLOCK : reviewsblock -->
Parent tpl file
parent tpl file for reviewsblock tpl is for example:
reviews.tpl
<!-- INCLUDE BLOCK : reviewsblock -->
Replace $tpl
replace it with new shortcode - any name not used somwhere
{reviewsblock_output}
We used reviewsblock_output
because the same name of variable used for this content.
At the end of block variables:
$reviewsblock_vars = array_change_key_case($reviewsblock_vars,CASE_UPPER);
it changes all keys to capitals
$reviewsblock_text = e107::getParser()->simpleParse($reviewsblock_template,$reviewsblock_vars, false);
it replaces shortcodes in tpl file
it let untouched not used shortcodes (3rd parameter is false}
$reviewsblock_text = e107::getParser()->parseTemplate($reviewsblock_text, true);
it replaces LANs shortcodes and not used shortcodes
$reviewsblock_output .= $reviewsblock_text;
this is output for one reviews. To get all reviews:
Get output to parent:
Find $tpl->gotoBlock( "_ROOT" );
$tpl->assign("reviewsblock_output", $reviewsblock_output);
Now:
check where reviewsblock is used and replace it with shortcode
move to fix parent similar way
Last updated