search
HomeBackend DevelopmentPHP TutorialSmarty Quick Start Part 2_PHP Tutorial
Smarty Quick Start Part 2_PHP TutorialJul 13, 2016 pm 05:43 PM
smartyforusegetting StartedloadCanWillfastusmoldof

In order to use smarty more conveniently in the future, we can put the three steps of "loading the Smarty template engine", "creating the Smarty object" and "setting the parameters of the Smarty object" into a public php file. We can just reuqire the place where it is used, for example:

1. Create a main.php

include smarty/Smarty.class.php;
//You only need to modify the ROOT pointing position next time the program is transplanted~
const DIR_SEP = DIRECTORY_SEPARATOR;
define (ROOT, D:.DIR_SEP._PHP_Test.DIR_SEP.Test2.DIR_SEP); $tpl = new Smarty();
$tpl->template_dir = ROOT.templates.DIR_SEP;
$tpl->complie_dir = ROOT.templates_c.DIR_SEP;
$tpl->config_dir = ROOT.configs.DIR_SEP;
$tpl->cache_dir = ROOT.cache.DIR_SEP;
$tpl->left_delimiter = < ;{;
$tpl->right_delimiter = }>;
?>

Note 1: Why use DIRECTORY_SEPARATOR here? (Click to view)

Note 2: left_delimiter and right_delimiter are left and right terminator variables, which can be defined as other strings (default is {}).

2. Under templates, create a new test.htm









3. Call the template page to fill in the title and content, and create a new test_smarty_1.php

require main.php;
$tpl->assign(title, New Message);
$tpl->assign(content, This is test smarty!);
$tpl->display(test.htm);
?>

You can also write like this

require main.php;
$tpl->assign(array(title=>NewMessage, content=>This is test smarty!));
$tpl ->display(test.htm);
?>

Output result:

The page title displays: NewMessage

The page content shows: This is test smarty!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478801.htmlTechArticleIn order to use smarty more conveniently in the future, we can change "Load Smarty Template Engine", "Create Smarty Object", Put these three steps of "setting parameters of Smarty object" into a common...
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
理解SpringBoot和SpringMVC之间的差异及比较理解SpringBoot和SpringMVC之间的差异及比较Dec 29, 2023 am 09:20 AM

对比SpringBoot与SpringMVC,了解它们的差异随着Java开发的不断发展,Spring框架已经成为了许多开发人员和企业的首选。在Spring的生态系统中,SpringBoot和SpringMVC是两个非常重要的组件。虽然它们都是基于Spring框架的,但在功能和使用方式上却有一些区别。本文将重点对比一下SpringBoot与Sprin

Vue3中的生命周期函数:快速掌握Vue3的生命周期Vue3中的生命周期函数:快速掌握Vue3的生命周期Jun 18, 2023 am 08:20 AM

Vue3是目前前端界最热门的框架之一,而Vue3的生命周期函数是Vue3中非常重要的一部分。Vue3的生命周期函数可以让我们实现在特定的时机触发特定的事件,增强了组件的高度可控性。本文将从Vue3的生命周期函数的基本概念、各个生命周期函数的作用和使用方法以及实现案例等方面进行详细探究和讲解,帮助读者快速掌握Vue3的生命周期函数。一、Vue3的生命周期函数的

win10电脑怎么快速切屏win10电脑怎么快速切屏Jul 10, 2023 am 08:21 AM

电脑怎么切屏?在使用电脑的时候,有的朋友会使用两个甚至三个显示屏,但是在使用的时候,就会遇到需要切换屏幕的问题,那么电脑怎么切屏呢?一些朋友不知道电脑快速切屏方法,所以本期将教大家win10电脑怎么快速切屏。win10电脑怎么快速切屏?具体的方法如下:1、外接显示屏以后,同时按下【Fn】+【F4】或者【win】+【P】即可选择外接显示器。2、第二种方法是,在桌面空白处鼠标右键,然后选择【屏幕分辨率】。3、然后在【多显示器】中,就能够切换屏幕了。以上就是小编带来的win10电脑怎么快速切屏的全部内

前端开发中sessionStorage的优点及应用案例分析前端开发中sessionStorage的优点及应用案例分析Jan 11, 2024 pm 02:51 PM

sessionStorage在前端开发中的优势与应用案例分析随着Web应用的发展,前端开发的需求也越来越多样化。前端开发人员需要使用各种工具和技术来提高用户体验,其中,sessionStorage是一个非常有用的工具。本文将介绍sessionStorage在前端开发中的优势,以及几个具体的应用案例。sessionStorage是HTML5提供的一种本地存储方

win7如何快速截屏win7如何快速截屏Jun 29, 2023 am 11:19 AM

win7如何快速截屏?win7系统之中有着很多便捷操作功能,可以为各位提供非常多样化的便捷服务。很多win7系统的用户在使用电脑的过程中,想要通过win7系统之中的快捷键进行截屏,但是却不清楚具体的快捷键是哪些,因此无法正常使用,那么,这些快捷截屏键究竟是哪些呢?下面小编就为各位带来win7快速截屏键介绍。win7快速截屏键介绍1、按Prtsc键截图这样获取的是整个电脑屏幕的内容,按Prtsc键后,可以直接打开画图工具,接粘贴使用。也可以粘贴在QQ聊天框或者Word文档中,之后再选择保存即可。2

分享PyCharm中快速注释代码的技巧,提高工作效率分享PyCharm中快速注释代码的技巧,提高工作效率Jan 04, 2024 pm 12:02 PM

效率提升!PyCharm中快速注释代码的方法分享在日常的软件开发工作中,我们经常需要注释掉一部分代码进行调试或者调整。如果手动逐行添加注释,这无疑会增加我们的工作量和耗费时间。而PyCharm作为一款强大的Python集成开发环境,提供了快速注释代码的功能,大大提升了我们的开发效率。本文将分享一些在PyCharm中快速注释代码的方法,并提供具体的代码示例。单

VUE3初学者必备的快速开发入门指南VUE3初学者必备的快速开发入门指南Jun 15, 2023 pm 04:38 PM

VUE3初学者必备的快速开发入门指南Vue是一款流行的JavaScript框架,它的易用性、高度定制性和快速开发模式使得它在前端开发中广受欢迎。而最新的Vue3则推出了更多强大的特性,包括性能优化、TypeScript支持、CompositionAPI以及更好的自定义渲染器等等。本篇文章将为Vue3初学者提供一份快速开发入门指南,帮助你快速上手Vue3开发

Laravel 8:快速入门指南Laravel 8:快速入门指南Jun 20, 2023 am 09:37 AM

Laravel是一个流行的PHP框架,它提供了许多工具和功能,以使开发Web应用程序变得更加轻松和快速。Laravel8已经发布,它带来了许多新的功能和改进。在本文中,我们将学习如何快速入门Laravel8。安装Laravel8要安装Laravel8,您需要满足以下要求:PHP&gt;=7.3MySQL&gt;=5.6或MariaDB&gt;=10.

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

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software