2011-08-25 70 views
0

如何在smarty中使用{function name =「money_fomart」value = $ money} {/ function}來格式化貨幣?如何在smarty中使用{function ...} {/ function}來形式化貨幣?

我已經在money_fomart中返回了錢,但該標籤沒有顯示它?

對不起,我可能沒有說清楚。我想在common.php中定義函數'money_fomart',並將其命名爲smarty tpl中的值,我可以嗎?

+0

讓我們看看你的函數定義更詳細,以及你如何調用這個函數。 –

回答

0
+0

$ smarty-> registerPlugin(「function」,「money_fomart」,「print_money_fomart」); http://www.smarty.net/docs/en/api.register.plugin.tpl知道了,謝謝。 – hamlet

0
{function name=money_fomart} 
<--{$data*2}--> 
{/function} 


{call name=money_fomart data=100} 

是不是?

+0

「fomart」?真? –

+0

編輯評論。 – TROODON

+0

謝謝!但我的意思是在我的common.php中調用函數'money_fomart'來格式化$ money,而不是在smarty tpl中定義函數 – hamlet

0

...但你有一個空的函數定義。

如果你想知道如何調用新創建的函數,那麼像這樣做:{money_format}

順便說一句,這一切都寫得很好的documentation

+0

謝謝Janis,我如何在common.php中定義函數'money_fomart',並將其命名爲smarty tpl格式的值? – hamlet

+0

有[不同類型的插件](http://www.smarty.net/docs/en/plugins.tpl)。我懷疑你只需要一個[修飾符](http://www.smarty.net/docs/en/plugins.modifiers.tpl)。要創建它,請在您的插件目錄中創建一個名爲modifier.money_format.php的文件(並閱讀文檔,以便知道要在其中寫入什麼函數)。之後你可以像這樣在模板中調用它:'$ var | money_format'。要在php腳本中使用該功能,只需插入以下行:'require_once(SMARTY_PLUGINS_DIR。'modifier.money_format.php');' –

+0

太好了,謝謝。如果我在我的func.php中添加money_fomart並註冊它,$ smarty-> registerPlugin(「modifier」,「money_fomart」,「money_fomart」);如果這有相同的效果,將會更方便 – hamlet