<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh">
	<id>https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=Smarty</id>
	<title>Smarty - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=Smarty"/>
	<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=Smarty&amp;action=history"/>
	<updated>2026-07-10T17:48:27Z</updated>
	<subtitle>在这个wiki上该页的修订历史</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://arolstar52-zhtest.hf.space/index.php?title=Smarty&amp;diff=271620&amp;oldid=prev</id>
		<title>imported&gt;C8H17OH：​/* 簡介 */ 增加或调整内部链接</title>
		<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=Smarty&amp;diff=271620&amp;oldid=prev"/>
		<updated>2022-09-07T10:12:44Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;簡介：​&lt;/span&gt; 增加或调整内部链接&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox Software&lt;br /&gt;
| name = Smarty Templates&lt;br /&gt;
| logo = [[File:smarty-logo.gif]]&lt;br /&gt;
| developer = Monte Ohrt, Messju Mohr&lt;br /&gt;
| latest_release_version = 3.1.27 &lt;br /&gt;
| latest_release_date = {{Release date and age|2015|06|19|df=yes}}&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/smarty-php/smarty/blob/v3.1.27/change_log.txt |title=存档副本 |accessdate=2015-08-07 |archive-date=2019-02-17 |archive-url=https://web.archive.org/web/20190217231514/https://github.com/smarty-php/smarty/blob/v3.1.27/change_log.txt |dead-url=no }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| genre = [[網頁模板引擎]]&lt;br /&gt;
| license = [[LGPL]]&lt;br /&gt;
| website = [http://smarty.net smarty.net]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Smarty&amp;#039;&amp;#039;&amp;#039;是一個[[PHP]]下的[[網頁模板]]系統。Smarty基本上是一種為了將不同考量的事情分離而推出的工具，這對某些應用程式是一種共通性設計策略。&amp;lt;ref&amp;gt;Smarty將[[PHP]]碼（{{link-en|事務邏輯|Business logic}}）與 [[HTML]]碼分開（通常代表{{link-en|表現邏輯|Presentation logic}}）.&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;Parr000&amp;quot;&amp;gt;{{cite book &lt;br /&gt;
        | first = Terence John&lt;br /&gt;
        | last = Parr&lt;br /&gt;
        | title = Enforcing strict model-view separation in template engines&lt;br /&gt;
        | publisher = Proceedings of the 13th international conference on World Wide Web&lt;br /&gt;
        | year = 2004&lt;br /&gt;
        | id = 1-58113-844-X&lt;br /&gt;
        }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 簡介 ==&lt;br /&gt;
Smarty以在文件中放置特殊的「Smarty標籤」來產生網頁內容。這些標籤會被處理並替換成其他的內容。&lt;br /&gt;
&lt;br /&gt;
標籤是給Smarty的指令符，以模板[[定界符]]包住。這些指令符可以是[[變數]]，以$符號代表函數、[[條件式語法|邏輯]]或 [[流程控制]]語法。Smarty允許PHP程式設計師以Smarty標籤去定義可存取的函數。&lt;br /&gt;
&lt;br /&gt;
Smarty意圖簡化[[區域化]]，允許PHP網頁後端邏輯與表現層（即[[使用者介面]]）分離。理想的情況下，這將降低軟體維護費用和人力。在這個研發策略之下，設計師可專注於實現表現層而不用撰寫PHP程式碼，並允許PHP程式設計師抽離出表現層並專注實現後端邏輯。&lt;br /&gt;
&lt;br /&gt;
Smarty支援幾個高階模板程式的特性，包含：&lt;br /&gt;
* [[正則表達式|正規表示法]]&lt;br /&gt;
* [[流程控制]]語法，如foreach、while。&lt;br /&gt;
* [[条件表达式|if]]，elseif，else&lt;br /&gt;
* 可修改的變數 - 例如{$variable|nl2br}&lt;br /&gt;
* 使用者自訂的函數&lt;br /&gt;
* 在模板內的數學計算&lt;br /&gt;
&lt;br /&gt;
以及其他特性。一些其他的[[網頁|模板引擎]]也支援這類特性。&lt;br /&gt;
&lt;br /&gt;
== 程式碼範例 ==&lt;br /&gt;
&lt;br /&gt;
因為 Smarty將 HTML碼與PHP程式碼分離，所以會有兩個檔案：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.1//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
   &amp;lt;title&amp;gt;{$title_text}&amp;lt;/title&amp;gt;&lt;br /&gt;
   &amp;lt;meta http-equiv=&amp;quot;content-type&amp;quot; content=&amp;quot;text/html; charset=iso-8859-1&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;body&amp;gt; {* This is a little comment that won&amp;#039;t be visible in the HTML source *}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;{$body_text}&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/body&amp;gt;&amp;lt;!-- this is a little comment that will be seen in the HTML source --&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
在企業邏輯程式碼中，設計者能配置Smarty去使用這個模板：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
define(&amp;#039;SMARTY_DIR&amp;#039;, &amp;#039;smarty-2.6.9/&amp;#039; );&lt;br /&gt;
require_once(SMARTY_DIR . &amp;#039;Smarty.class.php&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
$smarty = new Smarty();&lt;br /&gt;
$smarty-&amp;gt;template_dir = &amp;#039;./templates/&amp;#039;;&lt;br /&gt;
$smarty-&amp;gt;compile_dir = &amp;#039;./templates/compile/&amp;#039;;&lt;br /&gt;
$smarty-&amp;gt;cache_dir = &amp;#039;./templates/cache/&amp;#039;;&lt;br /&gt;
$smarty-&amp;gt;caching = false;&lt;br /&gt;
$smarty-&amp;gt;error_reporting = E_ALL; // LEAVE E_ALL DURING DEVELOPMENT&lt;br /&gt;
$smarty-&amp;gt;debugging = true;&lt;br /&gt;
&lt;br /&gt;
$smarty-&amp;gt;assign(&amp;#039;title_text&amp;#039;, &amp;#039;TITLE: This is the Smarty basic example ...&amp;#039;);&lt;br /&gt;
$smarty-&amp;gt;assign(&amp;#039;body_text&amp;#039;, &amp;#039;BODY: This is the message set using assign()&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
$smarty-&amp;gt;display(&amp;#039;index.tpl&amp;#039;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
並且能將PHP包涵在Smarty模板裡，像是下面這樣：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
{* We can use PHP syntax in smarty template inside {php} ..{/php} *}&lt;br /&gt;
{php} &lt;br /&gt;
$contentType = strpos($_SERVER[&amp;#039;HTTP_ACCEPT&amp;#039;]，&amp;#039;application/xhtml+xml&amp;#039;) === false ? &amp;#039;text/html&amp;#039; : &amp;#039;application/xhtml+xml&amp;#039;;&lt;br /&gt;
header(&amp;quot;Content-Type: $contentType; charset=utf-8&amp;quot;); &lt;br /&gt;
{/php}&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;lt;title&amp;gt;{$page_title}&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
   {$body_text}&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 參照 ==&lt;br /&gt;
{{reflist}}&lt;br /&gt;
&lt;br /&gt;
== 參見 ==&lt;br /&gt;
* [[內容管理系統]]&lt;br /&gt;
&lt;br /&gt;
== 外部連結 ==&lt;br /&gt;
=== 英文 ===&lt;br /&gt;
* [http://www.smarty.net/ Official site]{{Wayback|url=http://www.smarty.net/ |date=20111217045032 }}&lt;br /&gt;
* [https://web.archive.org/web/20061207024654/http://www.zend.com/zend/tut/tutorial-cezar.php &amp;#039;&amp;#039;PHP Templating with Smarty&amp;#039;&amp;#039;] by Cezar Floroiu - Smarty tutorial&lt;br /&gt;
* [http://www.devpapers.com/article/18 &amp;#039;&amp;#039;Smarty vs. XML/XSLT&amp;#039;&amp;#039;]{{Wayback|url=http://www.devpapers.com/article/18 |date=20070526053351 }} - from DevPapers.com by Sergey Makogon&lt;br /&gt;
* [http://hasin.wordpress.com/2006/06/10/smarty-cheat-sheet-version-20/ Smarty Cheat Sheet]{{Wayback|url=http://hasin.wordpress.com/2006/06/10/smarty-cheat-sheet-version-20/ |date=20070715121241 }} Smarty Cheat Sheet for Templates Designers and Programmers&lt;br /&gt;
* [https://web.archive.org/web/20070627161639/http://www.timestretch.com/php_intro/?page=smarty Timestretch: &amp;#039;&amp;#039;PHP, MySQL, and Smarty Programming&amp;#039;&amp;#039;] - Also see the PHP2 page for more.&lt;br /&gt;
* [http://www.nusphere.com/products/php_smarty.htm PHP Smarty Tools]{{Wayback|url=http://www.nusphere.com/products/php_smarty.htm |date=20070820043923 }} - Using Smarty in PhpED&lt;br /&gt;
&lt;br /&gt;
=== 中文 ===&lt;br /&gt;
* [https://web.archive.org/web/20170212091000/http://jaceju.net/2005-06-08-getting-started-with-smarty/ Smarty入門]&lt;br /&gt;
* [http://www.ecstart.com/ebook/SMARTYTEMPLATE_BIG5/ Smarty使用手冊]{{Wayback|url=http://www.ecstart.com/ebook/SMARTYTEMPLATE_BIG5/ |date=20071010131700 }}&lt;br /&gt;
* [https://web.archive.org/web/20110215200723/http://www.leapsoul.cn/?p=405 Smarty使用教程]&lt;br /&gt;
&lt;br /&gt;
[[Category:PHP]]&lt;br /&gt;
[[Category:網頁模板引擎]]&lt;/div&gt;</summary>
		<author><name>imported&gt;C8H17OH</name></author>
	</entry>
</feed>