我对整个php场景都很陌生,但我已经设法制作了一个php页眉和页脚,并将它们包含在我的页面上,所以我现在不必在每个页面上编辑页眉和页脚。我的下一个挑战是为像博客页面这样的东西制作一个完整的模板,如果我改变模板,那么所有的博客页面都会相应地改变,但内容当然必须保持不变,就像我拥有的php页眉和页脚一样。我读过一些关于主题引擎等的文章,但它们似乎都很令人困惑,我不想把它转换成wordpress。那么我有什么选择来制作一个模板呢?提前谢谢你。
发布于 2013-05-11 20:02:47
您可以简单地使用智能、强大的PHP模板引擎。First -创建具有html基础、页眉、页脚的模板。将其保存到template/_frame.html
<!DOCTYPE html>
<html>
<head>
<title>{block name='Title'}{/block} - My website</title>
</head>
<body>
<div>Header and some other stuff</div>
{block name='Content'}{/block}
<div>Footer and some other stuff</div>
</body>
</html>然后,为每个页面创建一个模板文件。如果它是一个博客,在每个页面上都有相同的外观,唯一可变的东西是帖子内容-你只需要一个模板。让我们称它为'Post.html‘。
{extends '_Frame.html'}
{block name='Title'}{$Post.Title|escape}{/block}
{block name='Content'}{$Post.Content}{/block}在php中-做这样的事情:
<?php
//Lets say at this poin you've got $BlogPost = array('Title' => 'Blog post title', 'Content' => 'Body of blog post')
$S = new Smarty();
$S->assign('Post', $BlogPost); //This creates new variable $Post which is availible inside templates.
$S->display('Post.html'); //this displays your template
?>
|escape - escapes all html in variable < goes ^lt; etc.https://stackoverflow.com/questions/16496442
复制相似问题