Smarty技巧篇

价格格式化:<{$test|number_format:2:".":","}>

    1. capitalize [首字符大寫]
      {$articleTitle}
      {$articleTitle|capitalize}
    2. count_characters [計算字數]
      {$articleTitle}
      {$articleTitle|count_characters}
      {$articleTitle|count_characters:true}
      第一個變數決定是否計算空格字符
    3. cat [連接字串]
      {$articleTitle|cat:" yesterday."}
    4. count_paragraphs [計算段落]
      {$articleTitle|cat:" yesterday."}
    5. count_sentences [計算句數]
      {$articleTitle}
      {$articleTitle|count_sentences}
    6. count_words [計算字數]
      {$articleTitle}
      {$articleTitle|count_words}
    7. date_format [格式化日期]
      {$smarty.now|date_format}
      {$smarty.now|date_format:"%A, %B %e, %Y"}
      {$smarty.now|date_format:"%H:%M:%S"}
      {$yesterday|date_format}
      {$yesterday|date_format:"%A, %B %e, %Y"}
      {$yesterday|date_format:"%H:%M:%S"}
    8. default [默認值]
      {$articleTitle|default:"no title"}
      {$myTitle|default:"no title"}
    9. escape [編碼] 用於html轉碼,url轉碼,在沒有轉碼的變數上轉換單引號,十六進制轉碼,十六進制美化,或者javascript轉碼。需設是html轉碼。 {$articleTitle}
      {$articleTitle|escape}
      {$articleTitle|escape:"html"} {* escapes & " ' < > *}
      {$articleTitle|escape:"htmlall"} {* escapes ALL html entities *}
      {$articleTitle|escape:"url"}
      {$articleTitle|escape:"quotes"}
      <a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
    10. indent [縮進]在每行縮進字符串,默認是4個字符。
      作為可選參數,你可以指定縮進字符數。
      作為第二個可選參數,你可以指定縮進用什麼字符代替。 {$articleTitle}

      {$articleTitle|indent}

      {$articleTitle|indent:10}

      {$articleTitle|indent:1:"\t"}
    11. lower [小寫]
      {$articleTitle}
      {$articleTitle|lower}
    12. nl2br [換行符替換成 <br />]
    13. regex_replace [正則替換]
      {$articleTitle}
      {$articleTitle|regex_replace:"/[\r\t\n]/":" "}
    14. replace [替換]
      {$articleTitle}
      {$articleTitle|replace:"Garden":"Vineyard"}
      {$articleTitle|replace:" ":" "}
    15. spacify [插空] 在字串的每個字之間插入空格或者其他的字串.
      {$articleTitle}
      {$articleTitle|spacify}
      {$articleTitle|spacify:"^^"}
    16. number_format [數字格式化] 第一個變數用來指定小數點的長度,會自動四捨五入
      {$number}
      {$number|number_format:1}
      {$number|number_format:2}
    17. string_format [字符串格式化]
      {$number}
      {$number|string_format:"%.2f"}
      {$number|string_format:"%d"}
    18. strip [去除(多餘空格)]
    19. strip_tags [去除html標籤]
    20. truncate [截取]
    21. upper [大寫]
      {$articleTitle}
      {$articleTitle|upper}
    22. wordwrap [行寬約束]
      可以指定段落的寬度(也就是多少個字一行,超過這個字數換行).預設 80.
      第二個參數可選,可以指定在約束點使用什麼字串 (預設是換行符\n).
      預設情況下smarty將截取到詞尾,如果想精確到設定長度的字符,請將第三個參數設為ture {$articleTitle}

      {$articleTitle|wordwrap:30}

      {$articleTitle|wordwrap:20}

      {$articleTitle|wordwrap:30:"<br>\n"}

      {$articleTitle|wordwrap:30:"\n":true}

posted on 2012-08-20 12:01  北国的秋天  阅读(336)  评论(0编辑  收藏  举报

导航