how to use Smarty better with PHP?

前端 未结 11 1833
孤街浪徒
孤街浪徒 2021-01-02 17:50

I found that using Smarty with PHP, sometimes extra time will need to be used for

1) using quite different syntax than PHP itself
2) need to check small cases, b

11条回答
  •  渐次进展
    2021-01-02 18:11

    Pros

    • No PHP in your HTML files (Allows both PHP and HTML identing)
    • Pipes {$var|default:"None selected"} {$var|urlencode}
    • Foreachelse: {foreach item=row from=$results}{$row.name}
      {foreachelse}No results{/foreach}
    • Themable websites/pages (Using only CSS has it limits)

    Cons

    • Other language syntax
    • Not always obvious code {"Y-m-d"|strftime:$timestamp} {$array|@var_dump}
    • Slight overhead

    I can highly recommend the "template" approach(mVc), but both Smarty and plain PHP are up for the task.

提交回复
热议问题