?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
void smarty_block_
name
(array $params, mixed $content, object &$smarty)
Block functions are functions of the form: {func} .. {/func}. In other
words, they enclose a template block and operate on the contents of
this block. Block functions take precedence over custom functions of
the same name, that is, you cannot have both custom function {func} and
block function {func} .. {/func}.
塊函數(shù)的形式是這樣的:{func} ..
{/func}。換句話說,他們用標(biāo)記圈起一個塊,然后對這個塊的內(nèi)容進行操作。塊函數(shù)優(yōu)先于同名的傳統(tǒng)函數(shù),即你不能同時有通明的傳統(tǒng)函數(shù){func}和塊函數(shù){func} ..
{/func}。
By default your function implementation is called twice by
Smarty: once for the opening tag, and once for the closing tag
(see &$repeat below how to change this).
默認地你的函數(shù)執(zhí)行被Smarty調(diào)用兩次:一次是在開始標(biāo)記,另一次是在結(jié)束標(biāo)記(參考下面的&$repeat怎樣改變這種情況)
Only the opening tag of the block function may have attributes. All
attributes passed to template functions from the template are contained
in the
$params
as an associative array. You can
either access those values directly, e.g.
$params['start'] or use
extract($params) to import them into the symbol
table. The opening tag attributes are also accessible to your function
when processing the closing tag.
塊函數(shù)僅開始標(biāo)記可以有屬性。所有從模板傳替給模板函數(shù)的屬性被囊括與一個集合數(shù)組參數(shù)中。你可以直接獲取其值,例如:$params['start']或者是用extract($params)將它們導(dǎo)入符號表中。當(dāng)處理結(jié)束標(biāo)記時,開始標(biāo)記的屬性對你的函數(shù)也是可用的。
The value of
$content
variable depends on
whether your function is called for the opening or closing tag. In case
of the opening tag, it will be null, and in case of
the closing tag it will be the contents of the template block.
Note that the template block will have already been processed by
Smarty, so all you will receive is the template output, not the
template source.
變量
$content
的值取決于是否因開始標(biāo)記或結(jié)束標(biāo)記調(diào)用你的函數(shù)。假如是開始標(biāo)記,它會是空的,如果是結(jié)束標(biāo)記,它會是模板塊的內(nèi)容。請注意模板塊已經(jīng)被Smarty處理,所以你接收到的結(jié)果是輸出后的模板而不是原樣模板。
The parameter
&$repeat
is passed by
reference to the function implementation and provides a
possibility for it to control how many times the block is
displayed. By default
$repeat
is
true at the first call of the block-function
(the block opening tag) and false on all
subsequent calls to the block function (the block's closing tag).
Each time the function implementation returns with
&$repeat
being true, the contents between
{func} .. {/func} are evaluated and the function implementation
is called again with the new block contents in the parameter
$content
.
參數(shù)
&$repeat
通過參考引用傳遞給函數(shù)執(zhí)行過程并為其提供一個可能值來控制顯示塊多少遍。默認情況下在首次調(diào)用塊函數(shù)(塊開始標(biāo)記)時變量
$repeat
是真,在隨后的所有塊函數(shù)調(diào)用中其始終是假。每當(dāng)函數(shù)執(zhí)行返回的
&$repeat
是真時,在{func} .. {/func}之間的內(nèi)容再次求值,函數(shù)執(zhí)行接收一個新塊參數(shù)
$content
內(nèi)容值被再次調(diào)用。
If you have nested block functions, it's possible to find out what the
parent block function is by accessing
$smarty->_tag_stack variable. Just do a var_dump()
on it and the structure should be apparent.
如果你嵌套了塊函數(shù),通過訪問變量$smarty->_tag_stack 找出父塊函數(shù)是可能的。僅僅對塊函數(shù)運行一下var_dump(),函數(shù)結(jié)構(gòu)就會一目了然了。
See also: register_block(), unregister_block().
Example 16-5. block function
|