Home Backend Development PHP Tutorial smarty turns out to be nothing more than that~~haha_PHP Tutorial

smarty turns out to be nothing more than that~~haha_PHP Tutorial

Jul 21, 2016 pm 03:59 PM
include once smarty Include

include_once("./comm/Smarty.class.php"); //Include smarty class files
$smarty = new Smarty(); //Create smarty instance object $smarty
$smarty->templates( "./templates"); //Set the template directory
$smarty->templates_c("./templates_c"); //Set the compilation directory
//****Attention everyone, I am the new member here****//
$smarty->cache("./cache"); //Set the cache directory
$smarty->cache_lifetime = 60 * 60 * 24; //Set the cache time
$smarty->caching = true; //Set the cache method
//----------------------------------------- --------------
//The left and right boundary characters, the default is {}, but in actual application it is easy to conflict with JavaScript
//, so it is recommended to set it to <{ }>or others.
//--------------------------------------------- -------
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
$smarty->assign(" name", "Li Xiaojun"); //Replace template variables
//Compile and display the index.tpl template located under ./templates
$smarty->display("index.tpl");
?>
We can see that the program part of smarty is actually a set of codes that conform to the PHP language specification. Let’s explain them in turn:
1. /**/Statement: The part contained in
is the program header comment. The main content should be a brief introduction to the function of the program, copyright, author and writing time. This is not necessary in smarty
, but in terms of the style of the program, this is a good style.
2. include_once statement:
It will include the smarty file installed on the website into the current file. Note that the included path must be written correctly.
3. $smarty = new Smarty():
This sentence creates a new Smarty object $smarty, which is a simple instantiation of an object.
4. $smarty->templates(""):
This sentence specifies the path of the $smarty object when using the tpl template. It is a directory. Without this sentence, Smarty's default template path is templates in the current directory
Directory, when actually writing a program, we need to specify this sentence. This is also a good programming style.
5. $smarty->templates_c(""):
This sentence specifies the directory where the $smarty object is compiled. In the template design chapter, we already know that Smarty is a compiled template language, and this directory is the directory where it compiles
templates. Note here that if the site is located on a *nix server, please ensure that this directory is defined in teamsplates_c It has writable and readable permissions. By default, its compilation directory
is templates_c in the current directory. For the same reason, we write it out explicitly.
6. $smarty->left_delimiter and $smarty->right_delimiter:
Indicates the left and right delimiters when looking for template variables. By default, it is "{" and "}", but in practice, because we need to use

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

What is the difference between php include and include_once What is the difference between php include and include_once Mar 22, 2023 am 10:38 AM

When we write web pages using PHP, sometimes we need to include code from other PHP files in the current PHP file. At this time, you can use the include or include_once function to implement file inclusion. So, what is the difference between include and include_once?

What are the necessary packages for jQuery to be introduced? What are the necessary packages for jQuery to be introduced? Feb 23, 2024 pm 12:00 PM

jQuery is a well-known JavaScript library that provides simple and powerful functions to simplify JavaScript programming. When introducing jQuery into your web project, you need to add the following code to the HTML file to introduce the necessary packages: My Web Page

A preliminary study on the template engine Smarty in PHP A preliminary study on the template engine Smarty in PHP May 11, 2023 pm 05:15 PM

Nowadays, website development is inseparable from an important component-template engine. A template engine refers to a tool that combines page templates and data to generate HTML code with a specific format. In various website development frameworks, the template engine is an essential component, because the template engine can greatly reduce the duplication of code and improve the dynamics of the page. One of the most common and popular template engines is Smarty. Smarty is a DSL (DomainSpecif

How to use PHP and Smarty to achieve front-end and back-end separation development How to use PHP and Smarty to achieve front-end and back-end separation development Jun 25, 2023 pm 01:46 PM

In modern web development, the separation of front-end and back-end has become a very popular trend, which allows developers to better organize projects and improve the efficiency of project development. PHP and Smarty are two very commonly used technologies, which can be used to achieve front-end and back-end separation development. This article will introduce how to use PHP and Smarty to achieve front-end and back-end separation development. What is front-end and back-end separation development? In traditional web development, the front-end is mainly responsible for the presentation of the page and the logic of interaction with the back-end. The backend is mainly responsible for the business

How to use Smarty template engine in PHP development How to use Smarty template engine in PHP development Jun 27, 2023 pm 01:28 PM

As a PHP developer, using a template engine is a natural choice. Smarty is a popular template engine that provides a way to separate HTML/CSS/JavaScript from PHP code, allowing developers to better organize and manage projects. In this article, we will learn how to use Smarty template engine during PHP development. 1. Install Smarty Before, we must install Smarty. In this article we will use Composer to install

How to tell if a string contains specific characters using JavaScript? How to tell if a string contains specific characters using JavaScript? Oct 21, 2023 am 08:23 AM

How to tell if a string contains specific characters using JavaScript? In JavaScript, we can use several methods to determine whether a string contains specific characters. Three commonly used methods will be introduced below and corresponding code examples will be given. Method 1: Use the indexOf() method You can use the indexOf() method of the string to determine whether a string contains the specified characters. It returns the index of the first occurrence of a specific character in a string, such as

How to use PHP and the Smarty template engine How to use PHP and the Smarty template engine May 11, 2023 pm 03:33 PM

PHP is a powerful server-side scripting language that can be used to develop web applications. In the early days of web development, programmers used a lot of HTML and JavaScript code to develop web applications. However, this approach is difficult to maintain and manage because the HTML and JavaScript code can become very complex. To solve this problem, the Smarty template engine was created. Smarty is a template engine developed based on PHP for managing and generating W

Application of template engine Smarty in PHP development Application of template engine Smarty in PHP development Jun 14, 2023 pm 02:02 PM

With the rapid development and upgrading of the Internet, PHP, as a programming language widely used in Web application development, has gradually become a very popular programming language in the industry. However, in the PHP development process, traditional code implementation methods often lead to a decrease in code readability and maintainability. At this time, an efficient template engine becomes one of the solutions. Among many template engines, Smarty has become a popular choice among PHP developers due to its powerful functions and good performance. This article will detail

See all articles