【发布时间】:2015-11-01 09:31:09
【问题描述】:
你好 stackoverflow 社区!
我无法找到这个问题的答案。我有一个如下所示的contact.php 文件:
<?php
require_once('lib/smarty/smarty/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->caching = false;
$smarty->debugging = false;
$smarty->template_dir = $_SERVER['DOCUMENT_ROOT'].'/templates/';
$smarty->compile_dir = $_SERVER['DOCUMENT_ROOT'].'/cache/smarty/templates_c';
$smarty->cache_dir = $_SERVER['DOCUMENT_ROOT'].'/cache/smarty/cache';
$smarty->display('contact.tpl');
die;
在我的contact.tpl 文件中,我有我的表单:
{extends file="index.tpl"}
{block name="content"}
my form....
{/block}
我通过一个名为 index.tpl 的主文件包含我的名为 content 的块:
<!DOCTYPE html>
<main>
...
{block name="content"}{/block}
</main>
问题: 一切正常,但是,在这种情况下,我必须创建大量显示正确模板的 php 文件(如 contact.php)。如何处理单个 php 文件,并根据用户单击的页面链接让它显示正确的模板?例如。当用户单击联系页面时,我希望它显示contact.tpl,当用户单击“关于”页面时,我希望它显示about.tpl,而无需为每种情况提供单独的php 文件。
【问题讨论】: