php - Smarty:如何在模板和链接中创建目录?
问题描述
我想在 Smarty 的默认模板目录中添加一个名为“locations”的新文件夹/目录。
为什么?
这样我就可以导航到我的新 页面: mywebsite.com/locations/new-post-here
但我根本无法让这些地点工作。
我已经在我的“模板”文件夹中创建了文件夹“位置”。这就是我为 Locations 创建新类时所拥有的。
<?php
require_once("libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->assign("title", "Locations");
$smarty->display("templates/locations.html");
?>
我得到的错误
内部服务器错误,500。
我还尝试了什么?
<?php
require_once("libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->setTemplateDir( dirname( __FILE__ ) . '/../templates/locations/' );
$smarty->assign("title", "Locations");
$smarty->display("/locations/new-post-here.html");
?>
不工作!
解决方案
目前尚不清楚文件在项目目录中的存储位置。无论如何,如果我们假设模板的默认文件夹是模板,那么您唯一要做的就是
$smarty->display("${location}/{$templateFile}");
您不必在显示路径前使用 /
<?php
require_once("libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->setTemplateDir( dirname( __FILE__ ) . '/../templates/locations/' );
$smarty->assign("title", "Locations");
$smarty->display("locations/new-post-here.html");
?>
但我不确定你的脚本在哪里
推荐阅读
- spring-boot - 在 DTO 响应中使用 Flux
- spring-boot - 通过复合主键的属性进行 Spring Data Cassandra 查询
- c# - winforms 应用程序中的相同活动
- angular - 有没有更好的方法让我按顺序执行多个 HTTP 请求?(角度 12)
- sql - pandas pivot_table SQL 等效项
- c - 结构如何分配自己?
- utf-16 - 对于大量 UTF-16 字符串(多语言),什么是合适的压缩算法?
- android - 有没有办法通过 Nearby Share 共享链接并使用 Nearby Connections API 通过第二台设备上的自定义应用程序接收链接?
- autofilter - 我可以从不同工作表上的范围设置 Autofilter Criteria1 吗?
- html - 使用 flex 阻止元素在同一行重叠