Get the App
SLTechnology News&Howtos  ›  Development  › 

Application of variables and variable modifiers in smarty template engine

Shulou Source: shulou.com Published: 2022-06-03 18:00:17 11月13日 Update

This article mainly explains the "smarty template engine variables and variable modifier example application", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "smarty template engine variables and variable modifier example application" it!

This paper gives an example of the application of smarty variable and variable modifier. Share it with you for your reference. The details are as follows:

Template file: temp.htm:

The copy code is as follows:

{config_load file= "foo.conf"} {$name.na1 | cat:$name ['na2']} {$name [' na1'] | cat:' and'| cat:$name.na2} {$na} {/ foreach} {$dog- > leee ()} {$dog- > name} {literal} function foobar {alert ('foobarring');} {/ literal} {# pageTitle#} dosomething pot {$smarty.server.SERVER_NAME} {$str | count_words}-constant-

{$smarty.now} {$smarty.const.MY_CONST} {$smarty.current_dir} {$smarty.version} {$smarty.ldelim | cat:$smarty.rdelim} {$smarty.now | date_format:$config} {$yesterday | date_format:'Y-m-d'} {$string | default:'default variable modifier: smarty Learning'} {$str1 | escape:'html'} {$str2 | escape:'mail'}

{$str1 | indent | upper}

{$str1 | nl2br} {$str1 | regex_replace: "/ @\ d {3} /": "ABC"} {$str1 | replace: "sina"} {$str1 | spacify} {$number | string_format: "% .2f"} {$number | string_format: "% d"} {$str3 | strip: "|"} remove the characters contained in between: {$str3 | truncate:10: "...": true} wrap by length: {$str3 | wordwrap:30: ""} {append var='name' value= "Bob" index= "first"} {append var='name' value= "John" index= "last"} {$name.last} {foreach from=$family item=home} {foreach from=$home item=person} {/ foreach} {/ foreach} {$family [1] .girl} {assign var= "name" value= "Zhang Sanfeng" php file: index.php copy code is as follows:

Tags: Variables instances templates applications engines code learning content constants files beauty length Sanfeng between characters puppies that is ideas situations members Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info vpn macOS NVidia Microsoft