search
HomeBackend DevelopmentPHP TutorialSmarty template engine assigns data types_PHP tutorial
Smarty template engine assigns data types_PHP tutorialJul 13, 2016 am 09:59 AM
smartymaindistributeenginedataarticletemplatetype

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);

字符串类型:

整型:

浮点型:

布尔类型真:

布尔类型假:

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:
Integer type:
Floating point type:
Boolean type true:
Boolean type false:
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:,元素2:,元素3:

关联数组取法1(不推荐):元素1:,元素2:,元素3:

关联数组取法2(推荐):元素1:,元素2:,元素3:

二维索引数组:

元素1:,

元素2:,

元素3:,

元素4:,

元素5:

关联二维数组形式1:

id-,

name-,

email-,

url-,

age-

关联二维数组形式2:

id-,

name-,

email-,

url-,

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: , Element 2: , Element 3:
Associative array method 1 (not recommended): Element 1: , Element 2: , Element 3:< ;{$arr2['city3']}>
Associative array selection method 2 (recommended): Element 1: , Element 2: , Element 3:
Two-dimensional index array: Element 1:, Element 2:, Element 3:, Element 4:, Element 5:
Associative two-dimensional array form 1: id-, name-, email-, url-, age-
Associative two-dimensional array form 2: id-, name-, email-, url-, 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-name}>,

age-age}>,

color-color}>

//数组属性

arr-arr[0]}>,

arr-arr[1]}>,

arr-arr[2]}>

//对象属性

object-master->name}>,

object-master->age}>

1 2

3

4

5

6 7

8

10 11 12
Object:
//Basic attributes name-name}>,
age-age}>,
color-color}>
//Array attribute arr-arr[0]}>, arr-arr[1]}>, arr-arr[2]}>
//Object properties object-master->name}>, object-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
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
PPT蒙版要怎么添加PPT蒙版要怎么添加Mar 20, 2024 pm 12:28 PM

关于PPT蒙版,很多人肯定对它很陌生,一般人做PPT不会将它吃透,而是凑活着可以做出来自己喜欢的就行,所以很多人都不知道PPT蒙版到底是什么意思,也不知道这个蒙版有什么作用,甚至更不知道它可以让图片变得不再那么单调,想要学习的小伙伴们快来了学习学习,为你的PPT图片上添上点吧PPT蒙版吧,让它不再单调了。那么,PPT蒙版要怎么添上呢?请往下看。1.首先我们打开PPT,选择一张空白的图片,之后右键点击【设置背景格式】,纯色选择颜色就行。2.点击【插入】,艺术字,输入字3.点击【插入】,点击【形状】

C++ 模板特化的影响对于函数重载和重写C++ 模板特化的影响对于函数重载和重写Apr 20, 2024 am 09:09 AM

C++模板特化影响函数重载和重写:函数重载:特化版本可提供特定类型不同的实现,从而影响编译器选择调用的函数。函数重写:派生类中的特化版本将覆盖基类中的模板函数,影响派生类对象调用函数时的行为。

如何在 OneNote 中使用模板来提高工作效率如何在 OneNote 中使用模板来提高工作效率Apr 30, 2023 am 11:31 AM

您是否知道使用模板可以提高记笔记的速度以及捕捉重要想法的效率?OneNote有一套现成的模板供您使用。最好的部分是您还可以根据需要设计模板。无论您是学生、企业战士还是从事创造性工作的自由职业者。OneNote模板可用于以适合您风格的结构和格式记录重要笔记。模板可以是记笔记过程的大纲。业余爱好者只是做笔记,专业人士则在模板的帮助下通过结构良好的笔记做笔记并从中汲取联系。让我们看看如何在OneNote中使用模板。使用默认OneNote模板第1步:按键盘上的Windows+R。键入Oneno

PHP电子邮件模板:定制化和个性化您的邮件内容。PHP电子邮件模板:定制化和个性化您的邮件内容。Sep 19, 2023 pm 01:21 PM

PHP电子邮件模板:定制化和个性化您的邮件内容随着电子邮件的普及和广泛应用,传统的邮件模板已经不能满足人们对个性化和定制化邮件内容的需求。现在,我们可以通过使用PHP编程语言来创建定制化和个性化的电子邮件模板。本文将为您介绍如何使用PHP来实现这一目标,并提供一些具体的代码示例。一、创建邮件模板首先,我们需要创建一个基本的邮件模板。这个模板可以是一个HTM

Flask-Bootstrap:为Flask应用程序添加模板Flask-Bootstrap:为Flask应用程序添加模板Jun 17, 2023 pm 01:38 PM

Flask-Bootstrap:为Flask应用程序添加模板Flask是一个轻量级的PythonWeb框架,它提供了一个简单而灵活的方式来构建Web应用程序。它是一款非常受欢迎的框架,但它的默认模板功能有限。要创建富有吸引力的用户界面,需使用其他框架或库。这就是Flask-Bootstrap的用武之地。Flask-Bootstrap是一个基于Twitter

Vue中如何实现图片的模板和蒙版处理?Vue中如何实现图片的模板和蒙版处理?Aug 17, 2023 am 08:49 AM

Vue中如何实现图片的模板和蒙版处理?在Vue中,我们经常需要对图片进行一些特殊的处理,例如添加模板效果或者加上蒙版。本文将介绍如何使用Vue实现这两种图片处理效果。一、图片模板处理在使用Vue处理图片时,我们可以利用CSS的filter属性来实现模板效果。filter属性给元素添加图形效果,其中的brightness滤镜可以改变图片的亮度。我们可以通过改变

C++中的模板元编程面试常见问题C++中的模板元编程面试常见问题Aug 22, 2023 pm 03:33 PM

C++是一门广泛应用于各个领域的编程语言,其模板元编程是一种高级编程技术,可让程序员在编译时对类型和数值进行变换。在C++中,模板元编程是一个广泛讨论的话题,因此在面试中,与此相关的问题也是相当常见的。以下是一些可能会被问到的C++中的模板元编程面试常见问题。什么是模板元编程?模板元编程是一种在编译时操作类型和数值的技术。它使用模板和元函数来根据类型和值生成

一甜相机收藏的模板在哪里一甜相机收藏的模板在哪里Feb 23, 2024 pm 03:13 PM

一甜相机中可以收藏很多的模版,那么收藏的模版位置在什么地方呢?用户们需要点击修图,在里面能够看到很多模版,找到有图标的模版就是收藏的模版,这篇收藏的模板位置介绍就能够告诉大家具体的内容,下面就是详细的介绍,赶紧来看看吧。一甜相机使用教程一甜相机收藏的模板在哪里答:在修图里能够看到自己收藏的模版具体方法:1、首先在软件里点击修图功能。2、在上面能够看到很多的模版。3、在里面能够看到有星的符号,就能找到收藏的模版。

See all articles

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 agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools