Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the Smarty template functions

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about the Smarty template function, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Let's take a look at it.

Recently, I used Smarty template engine in my work and sorted out some template functions used.

Assume that the delimiter of smarty is {}.

Get the value of server $_ GET from the template:

{$smarty.get. Parameter name}

Get the value of server $_ POST from the template:

{$smarty.post. Parameter name}

Get the value of server $_ REQUEST from the template:

/ / request can get the value of get or post. {$smarty.request. Parameter name}

Get the value of server $_ SESSION from the template:

{$smarty.session. Parameter name}

Get the value of server $_ COOKIE from the template:

{$smarty.cookies. Parameter name}

Get the value of server $_ SERVER from the template:

{$smarty.server. Parameter name}

Convert the timestamp to Y-m-d H:i:s in the template:

{$Parameter name | date_format:'%Y-%m-%d% HRV% MRO% S'}

Convert the string to lowercase in the template:

{$Parameter name | lower}

Convert the string to uppercase in the template:

{$Parameter name | upper}

Convert the first letter of the string to uppercase in the template:

{$Parameter name | capitalize}

Add characters to the template after the string:

{$parameter name | cat:' string'}

Set the default value in the template if the variable is empty or does not exist:

{$parameter name | default:' string'}

The length of the string in the template is more than 20 and is hidden behind. Connection:

{$Parameter name | truncate:23: "...": true}

Convert the HTML in the string to HTML encoding in the template:

{$Parameter name | escape:html}

Convert the HTML in the string to URL encoding in the template:

{$Parameter name | escape:url}

Replace characters with regular expressions in the template:

{$Parameter name | regex_replace: "/ string 1 /": "string 2"}

Use Replace to replace characters in the template:

{$parameter name | replace: "string 1": "string 2"}

Formatted numbers in the template are of type Float (rounding retains two decimal places)

{$Parameter name | string_format: "% .2f"}

The formatted number in the template is of type Int (if there is a decimal place, it will be dropped)

{$Parameter name | string_format: "% d"}

If the {} of js conflicts with the smarty delimiter:

(1) modify the delimiter to (2) to include the JS code between {literal} {/ literal}. These are the Smarty template functions, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report