Php Smarty不起作用

Php Smarty不起作用,php,smarty,extends,Php,Smarty,Extends,我在Smarty的遗产不起作用 以下是模板文件: ./views/parent.tpl /视图/模块/child.tpl 这就是我的孩子。tpl= /* child.tpl */ {extends file='../parent.tpl'} {block name='contents_accueil'} <article> <p>Something here</p> </article> {/block} 正如索夫所说,你把smarty模板继

我在Smarty的遗产不起作用

以下是模板文件:

./views/parent.tpl /视图/模块/child.tpl

这就是我的孩子。tpl=

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

<article>
<p>Something here</p>
</article>

{/block}

正如索夫所说,你把smarty模板继承搞错了。您必须显示child.tpl,而不是父级,因为父级可用于多个child,即child2.tpl将类似于:

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

<article>
<p>Something completely different here</p>
</article>

{/block}
{extends file='../parent.tpl'}
{block name='contents\u accueil'}
这里有些完全不同的东西

{/block}

如你所见,只有孩子们掌握了所有信息。如果您只是显示parent.tpl,smarty对作为子文件使用的文件没有任何线索。把{extends}想象成一个容器include

块名应该被引用,
{extends file='../layout.tpl'}
转到layout.tpl而不是parent.tpl>我编辑了它但没有工作你得到了什么错误?告诉我们调用模板的php代码($smarty->display)我用php文件编辑了我的文章。我没有错误,只是child.tpl似乎没有出现
require_once('application/librairies/tpl/Smarty.class.php');
require_once('config.inc.php');

$data=array();
$smarty=new Smarty();

if(isset($_GET['page'])) {
    $current_page=$_GET['page'];
} 

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

$smarty->assign('data', $data);
$smarty->display('./application/views/parent.tpl');
{extends file='../parent.tpl'}
{block name='contents_accueil'}

<article>
<p>Something completely different here</p>
</article>

{/block}