> For the complete documentation index, see [llms.txt](https://playground.e107sk.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://playground.e107sk.com/e107-efiction-integration/template-power/templatepower.md).

# 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 -&#x20;

```
        /* 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;
         
        } 
```

{% hint style="info" %}
It is possible that paths will be changed in future. After full testing this approach.
{% endhint %}

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");`&#x20;

`$reviewsblock_output = "";`

{% hint style="info" %}
original tpl name was "reviewblock", so not to get lost in tpls hierarchy, all variables related to this tpl are named with the same name.
{% endhint %}

It is just copy of $tpl->assign()

Example:

from:

`$tpl->newBlock("reviewsblock")`

to

`$reviewsblock_vars = array();`

{% hint style="info" %}
for each block set new variable set
{% endhint %}

From:

`$tpl->assign("reviewer" , $reviewer );`

to:

$`reviewsblock_vars['reviewer'] = $reviewer;`

This is just manual stuff.&#x20;

## 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

{% hint style="info" %}
This is not mandatory. SimpleParser() doesn't need this. We need this for languages string and hiding not used shortcodes
{% endhint %}

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&#x20;

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