|   | 
              
                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的方法很簡單,直接寫{_('字符串')}就行了
 |