PHP language--smarty variable

Source: Internet
Author: User
Tags php language naming convention

test.php

<? PHP include ("init.inc.php");
Indexed array $attrArray (1,2,3,4,5); $smarty->assign ("Shuzu",$attr);
Associative arrays
$attr 2 = Array ("A" =>1, "B" =>2, "C" =>3, "D" =>4, "E" =>5);
$smarty->assign ("Shuzu2", $attr 2);

$r = new Ren ();

$smarty->assign ("Ren", $r);//Registered Object

$smarty->assign ("Test", "This is a demo");

$smarty->assign ("Money", 100);

$smarty->assign ("Biaoti", "Fdafdafdsagdasfdasgdafdsagdagds");

$smarty->assign ("BS", 1)


Class Ren
{
Public $name = ' Zhang San ';
}

$smarty->display (test.html);

Test.html

<body>$shuzu[0]} >//take an indexed array



<{config_load file= ' config file name. conf ' section= ' BB '}>//Load profile, section get a block

<div style= "width:200px; height:200px;background-color:<{#bg #}>;font-size:<{#size #}>px "> Test configuration </div>//<{#配置名 #} > or <{$smarty .config.bg}> reserved variables

<{$smarty. Now|date_format: "%y-%m-%d%h:%m:%s"}>//Go to current time return timestamp date_format format string

<{$test |capitalisze}>//variable adjuster format variable name | Adjuster Name Capitalize first letter capital

<{$money |cat: "¥"}>//variable name: Parameter Cat connection string

<{$test |mark}>//Calling custom variables

<{$biaoti |substr:10}>//Call Intercept String custom method

Use if else to pay attention to closure
<{if $bs ==1}>

<div>111111</div>

<{else}>

<div>222222</div>

<{/if}>

foreach Traversal array
<div>

<{foreach $shuzu as $k = $v}>

<div><{$k}><{$v}></div>

<{[email protected]}>//Take an index of an array

<{[email protected]}>//Take iteration count (loop order)

<{[email protected]}>//Determine which is the first data

<{/foreach}>

</div>


</body>

Configuration file

[AA]//block BG=redsize=24[BB]//block BG=yellowsize=36

Custom variable adjuster starts with modifier

Create a new file under the custom plugin directory named modifier. custom file name. PHP Note Naming conventions

<? PHP function smarty_modifier_mark ($str// at least one parameter, which represents the variable itself, takes care of the naming convention {  Return "<mark>{$str}</mark>"}

modifier.substr.php

<? PHP function smarty_modifier_substr ($str,$n//$n represents length {$str  substr($str, 0,$n-3); return $str. " ...";}

PHP language--smarty variable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.