作者共发了4篇帖子。 内容转换:不转换▼
 
点击 回复
322 3
Smarty最簡單的使用方法
一派护法 十九级
1楼 发表于:2015-10-25 11:32
把smarty壓縮包下載下來后解壓,把libs文件夾放到自己網站的根目錄下(或者也可以把文件夾的名稱換掉,比如“根目錄/includes/libraries/smarty”)。然後在網站根目錄下建立一個templates文件夾,專門用來存放HTML頁面模板。
打開templates文件夾,在其中創建以下三個文件夾:
templates_c
config
cache
然後創建一個index.tpl的HTML模板文件,內容如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>My First Smarty Page</title>
</head>

<body>
<header>
  <h2>My First Smarty Page </h2>
</header>
<main>
  <article>
    <section>Content for New main Tag Goes Here</section>
    <section>{$hello}</section>
  </article>
</main>
</body>
</html>

一派护法 十九级
2楼 发表于:2015-10-25 11:34
在根目錄下建立index.php文件作為瀏覽器訪問的頁面,內容如下:
<?php
date_default_timezone_set('UTC');
require_once 'libs/Autoloader.php';
Smarty_Autoloader::register();
$smarty = new Smarty();
$smarty->template_dir = 'templates';
$smarty->compile_dir ="templates/templates_c";
$smarty->config_dir = "templates/config";
$smarty->cache_dir ="templates/cache";
$hello = 'I\'d like to say Hello. How are your <b>feelings</b>?';
$smarty->assign('hello', $hello);
$smarty->display('index.tpl');
注意文件末尾不要加“?>”

$smarty->compile_dir ="templates/templates_c";這句話最好不要去掉,否則templates_c會出現在網站的根目錄下,很難看
一派护法 十九级
3楼 发表于:2015-10-25 11:36
然後瀏覽器訪問http://localhost:81/index.php,輸出的內容如下
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>My First Smarty Page</title>
</head>

<body>
<header>
  <h2>My First Smarty Page </h2>
</header>
<main>
  <article>
    <section>Content for New main Tag Goes Here</section>
    <section>I'd like to say Hello. How are your <b>feelings</b>?</section>
  </article>
</main>
</body>
</html>

一派护法 十九级
4楼 发表于:2015-10-27 23:06
smarty調用gettext的方法很簡單,直接寫{_('字符串')}就行了

回复帖子

内容:
用户名: 您目前是匿名发表
验证码:
(快捷键:Ctrl+Enter)
 

本帖信息

点击数:322 回复数:3
评论数: ?
作者:巨大八爪鱼
最后回复:巨大八爪鱼
最后回复时间:2015-10-27 23:06
 
©2010-2024 Arslanbar Ver2.0
除非另有声明,本站采用知识共享署名-相同方式共享 3.0 Unported许可协议进行许可。