Table of Contents
The allocation data type of smarty template engine
Home Backend Development PHP Tutorial Smarty template engine assigns data types_PHP tutorial

Smarty template engine assigns data types_PHP tutorial

Jul 13, 2016 am 09:59 AM
smarty main distribute engine data article template type

The allocation data type of smarty template engine

This article mainly introduces the allocation data type of smarty template engine, and analyzes the usage skills of smarty template engine data type with examples. For reference value, friends in need can refer to it

The example in this article describes the usage of allocated data types by smarty template engine. Share it with everyone for your reference. The specific analysis is as follows:

1. Distribute basic data

?

1

2

3

4

5

6

7

8

9

10

11

//分配基本数据

$smarty->assign("str","hello smarty!");

$smarty->assign("int",143);

$smarty->assign("double",12.1344);

$smarty->assign("bool",true);

$smarty->assign("bool2",false);

字符串类型:<{$str}>

整型:<{$int}>

浮点型:<{$double}>

布尔类型真:<{$bool}>

布尔类型假:<{$bool2}>

1 2

3

4smarty模板引擎之分配数据类型    帮客之家

5

6

7

8

9

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

//索引数组

$res=array('上海','北京','深圳');

$smarty->assign("arr",$res);

//关联数组

$res2=array('city1'=>'北京','city2'=>'广州','city3'=>'湖南');

$smarty->assign("arr2",$res2);

//索引二维数组

$res3 = array(

array('潇晓','常山','吴蓓'),array('珊珊','常明')

);

$smarty->assign("arr3",$res3);

//关联二维数组

$res4 = array(

array('id'=>'001','name'=>'张三','email'=>'zhangsan@1163.com'),

array('url'=>'http://www.baidu.com','age'=>'28')

);

$smarty->assign("arr4",$res4);

//关联二维数组2

$res5=array(

'emp1'=>array('id'=>'001','name'=>'张三','email'=>'zhangsan@1163.com'),

'emp2'=>array('url'=>'http://www.baidu.com','age'=>'28')

);

$smarty->assign("arr5",$res5);

10 11
//Assign basic data $smarty->assign("str","hello smarty!"); $smarty->assign("int",143); $smarty->assign("double",12.1344); $smarty->assign("bool",true); $smarty->assign("bool2",false); String type: <{$str}>
Integer type: <{$int}>
Floating point type: <{$double}>
Boolean type true: <{$bool}>
Boolean type false: <{$bool2}>
The browser displays the result: 1 means true, 0 means false. When false, it is null and nothing is displayed. 2. Distribute array of composite data ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 //Index array $res=array('Shanghai','Beijing','Shenzhen'); $smarty->assign("arr",$res); //Associative array $res2=array('city1'=>'Beijing','city2'=>'Guangzhou','city3'=>'Hunan'); $smarty->assign("arr2",$res2); //Index two-dimensional array $res3 = array( array('Xiaoxiao','Changshan','Wu Bei'), array('Shanshan','Changming') ); $smarty->assign("arr3",$res3); //Associated two-dimensional array $res4 = array( array('id'=>'001','name'=>'Zhang San','email'=>'zhangsan@1163.com'), array('url'=>'http://www.baidu.com','age'=>'28') ); $smarty->assign("arr4",$res4); //Associated two-dimensional array 2 $res5=array( 'emp1'=>array('id'=>'001','name'=>'Zhang San','email'=>'zhangsan@1163.com'), 'emp2'=>array('url'=>'http://www.baidu.com','age'=>'28') ); $smarty->assign("arr5",$res5);

Template file

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

索引数组:元素1:<{$arr[0]}>,元素2:<{$arr[1]}>,元素3:<{$arr[2]}>

关联数组取法1(不推荐):元素1:<{$arr2['city1']}>,元素2:<{$arr2['city2']}>,元素3:<{$arr2['city3']}>

关联数组取法2(推荐):元素1:<{$arr2.city1}>,元素2:<{$arr2.city2}>,元素3:<{$arr2.city3}>

二维索引数组:

元素1:<{$arr3[0][0]}>,

元素2:<{$arr3[0][1]}>,

元素3:<{$arr3[0][2]}>,

元素4:<{$arr3[1][0]}>,

元素5:<{$arr3[1][1]}>

关联二维数组形式1:

id-<{$arr4[0].id}>,

name-<{$arr4[0].name}>,

email-<{$arr4[0].email}>,

url-<{$arr4[1].url}>,

age-<{$arr4[1].age}>

关联二维数组形式2:

id-<{$arr5.emp1.id}>,

name-<{$arr5.emp1.name}>,

email-<{$arr5.emp1.email}>,

url-<{$arr5.emp2.url}>,

age-<{$arr5.emp2.age}>

1 2

3

4

5

6

7

8

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

class Master{

var $name;

var $age;

function __construct($name,$age){

$this->name=$name;

$this->age=$age;

}

}

class Dog{

var $name;

var $age;

var $color;

var $arr;

var $master;

function __construct($name,$age,$color,$arr6,$master){

$this->name=$name;

$this->age=$age;

$this->color=$color;

$this->arr=$arr6;

$this->master=$master;

}

}

$arr6=array('001','002','003');

$master = new Master('小明',22);

$dog1 = new Dog('小白',1,'white',$arr6,$master);

$smarty->assign("dog",$dog1);

9 10 11 12 13 14 15 16 17 18 19 20 21
Index array: Element 1: <{$arr[0]}>, Element 2: <{$arr[1]}>, Element 3: <{$arr[2]}>
Associative array method 1 (not recommended): Element 1: <{$arr2['city1']}>, Element 2: <{$arr2['city2']}>, Element 3:< ;{$arr2['city3']}>
Associative array selection method 2 (recommended): Element 1: <{$arr2.city1}>, Element 2: <{$arr2.city2}>, Element 3: <{$arr2.city3} >
Two-dimensional index array: Element 1:<{$arr3[0][0]}>, Element 2:<{$arr3[0][1]}>, Element 3:<{$arr3[0][2]}>, Element 4:<{$arr3[1][0]}>, Element 5:<{$arr3[1][1]}>
Associative two-dimensional array form 1: id-<{$arr4[0].id}>, name-<{$arr4[0].name}>, email-<{$arr4[0].email}>, url-<{$arr4[1].url}>, age-<{$arr4[1].age}>
Associative two-dimensional array form 2: id-<{$arr5.emp1.id}>, name-<{$arr5.emp1.name}>, email-<{$arr5.emp1.email}>, url-<{$arr5.emp2.url}>, age-<{$arr5.emp2.age}>
The browser displays the result: 3. Allocate composite data objects ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 class Master{ var $name; var $age; function __construct($name,$age){ $this->name=$name; $this->age=$age; } } class Dog{ var $name; var $age; var $color; var $arr; var $master; function __construct($name,$age,$color,$arr6,$master){ $this->name=$name; $this->age=$age; $this->color=$color; $this->arr=$arr6; $this->master=$master; } } $arr6=array('001','002','003'); $master = new Master('Xiao Ming',22); $dog1 = new Dog('小白',1,'white',$arr6,$master); $smarty->assign("dog",$dog1);

Template file

?

1

2

3

4

5

6

7

8

9

10

11

12

对象:

//基本属性

name-<{$dog->name}>,

age-<{$dog->age}>,

color-<{$dog->color}>

//数组属性

arr-<{$dog->arr[0]}>,

arr-<{$dog->arr[1]}>,

arr-<{$dog->arr[2]}>

//对象属性

object-<{$dog->master->name}>,

object-<{$dog->master->age}>

1 2

3

4

5

6 7

8

10 11 12
Object:
//Basic attributes name-<{$dog->name}>,
age-<{$dog->age}>,
color-<{$dog->color}>
//Array attribute arr-<{$dog->arr[0]}>, arr-<{$dog->arr[1]}>, arr-<{$dog->arr[2]}>
//Object properties object-<{$dog->master->name}>, object-<{$dog->master->age}>
Browser displays results I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/976535.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/976535.htmlTechArticleThe allocation data type of smarty template engine This article mainly introduces the allocation data type of smarty template engine and analyzes the examples Tips for using smarty template engine data types, with certain parameters...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Apr 03, 2024 pm 12:04 PM

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

Use ddrescue to recover data on Linux Use ddrescue to recover data on Linux Mar 20, 2024 pm 01:37 PM

DDREASE is a tool for recovering data from file or block devices such as hard drives, SSDs, RAM disks, CDs, DVDs and USB storage devices. It copies data from one block device to another, leaving corrupted data blocks behind and moving only good data blocks. ddreasue is a powerful recovery tool that is fully automated as it does not require any interference during recovery operations. Additionally, thanks to the ddasue map file, it can be stopped and resumed at any time. Other key features of DDREASE are as follows: It does not overwrite recovered data but fills the gaps in case of iterative recovery. However, it can be truncated if the tool is instructed to do so explicitly. Recover data from multiple files or blocks to a single

Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Apr 01, 2024 pm 07:46 PM

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks Apr 29, 2024 pm 06:55 PM

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

Slow Cellular Data Internet Speeds on iPhone: Fixes Slow Cellular Data Internet Speeds on iPhone: Fixes May 03, 2024 pm 09:01 PM

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. May 07, 2024 pm 05:00 PM

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,

Alibaba 7B multi-modal document understanding large model wins new SOTA Alibaba 7B multi-modal document understanding large model wins new SOTA Apr 02, 2024 am 11:31 AM

New SOTA for multimodal document understanding capabilities! Alibaba's mPLUG team released the latest open source work mPLUG-DocOwl1.5, which proposed a series of solutions to address the four major challenges of high-resolution image text recognition, general document structure understanding, instruction following, and introduction of external knowledge. Without further ado, let’s look at the effects first. One-click recognition and conversion of charts with complex structures into Markdown format: Charts of different styles are available: More detailed text recognition and positioning can also be easily handled: Detailed explanations of document understanding can also be given: You know, "Document Understanding" is currently An important scenario for the implementation of large language models. There are many products on the market to assist document reading. Some of them mainly use OCR systems for text recognition and cooperate with LLM for text processing.

Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! May 06, 2024 pm 04:13 PM

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

See all articles