strip

Many times web designers run into the issue where white space and carriage returns affect the output of the rendered HTML (browser "features"), so you must run all your tags together in the template to get the desired results. This usually ends up in unreadable or unmanageable templates.

很多時候網頁設計者會對於是否要移除掉導致 HTML 語法散亂的空白鍵與回覆 鍵等等的覺得很困擾,為了避免發生此種狀況,所以你可以將所有的標籤集中在一起以達成你想 要的網頁輸出結果,如此一來將可以避免產生不易閱讀或不易管理的樣板檔。

Anything within {strip}{/strip} tags in Smarty are stripped of the extra spaces or carriage returns at the beginnings and ends of the lines before they are displayed. This way you can keep your templates readable, and not worry about extra white space causing problems.

任何 {strip}{/strip} 標籤內的內容在輸出前,在每行的開始或結束位置只 要有多餘的空白鍵或回覆鍵都會被去除。如此一來除了可保持樣版檔的可讀性外,也不必擔心因 為多餘的空白鍵所造成的其他問題。

Technical Note: {strip}{/strip} does not affect the contents of template variables. See the strip modifier function.

技術提醒: {strip}{/strip} 不會影響樣板變數的內容。請參閱 strip modifier function.

Example 7-31. strip 標籤

{* the following will be all run into one line upon output *}
{strip}
<table border=0>
	<tr>
		<td>
			<A HREF="{$url}">
			<font color="red">This is a test</font>
			</A>
		</td>
	</tr>
</table>
{/strip}


OUTPUT:

<table border=0><tr><td><A HREF="http://my.example.com"><font color="red">This is a test</font></A></td></tr></table>

Notice that in the above example, all the lines begin and end with HTML tags. Be aware that all the lines are run together. If you have plain text at the beginning or end of any line, they will be run together, and may not be desired results.

請注意上方的範例,每一行的開始與結束都是使用 HTML 標籤,在使用 strip 標 籤之後將會連在一起。如果你在每行的開始與結束的地方加入文字的話,使用 strip 標籤之後 依然會被連在一起,但是可能不會呈現我們想要的結果。