Choubidou Choubidou - 6 months ago 48
PHP Question

Smarty extends not works

My inheritance in Smarty doesn't work,

These are the template files:


So this is my child.tpl =

/* child.tpl */
{extends file='../parent.tpl'}
{block name='contents_accueil'}

<p>Something here</p>


And my parent.tpl :

<p>Something else</p>
{block name='contents_accueil'}{/block}

Why does it not work? It does not include my child.tpl file.


The file php which calls the parent.tpl


$smarty=new Smarty();

if(isset($_GET['page'])) {

$data = (isset($current_page)) ? $_PAGES[$current_page] : $data=HOME_PAGE;

$smarty->assign('data', $data);

Answer Source

As sofl said, you got smarty template inheritance wrong. You have to display the child.tpl, not the parent, because the parent can be used for multiple childs, i.e. child2.tpl will look like:

{extends file='../parent.tpl'}
{block name='contents_accueil'}

<p>Something completely different here</p>


As you see, childs are the only ones that have all the information. If you just display parent.tpl, smarty doesn't have any clue about what file use as child. Think of {extends} as a container include

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download