目前共有4篇帖子。 內容轉換:不轉換▼
 
點擊 回復
304 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)
 

本帖信息

點擊數:304 回複數:3
評論數: ?
作者: 巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2015-10-27 23:06
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。