Brief Analysis of Smarty Template Configuration Example

  • 2021-12-13 07:34:45
  • OfStack

This article illustrates the Smarty template configuration. Share it for your reference, as follows:

Introduction to Smarty

Smarty is an php template engine. More precisely, it separates the logic program from the external content, providing an easy-to-manage approach. It can be described as an application programmer and an artist playing different roles, because in most cases, they can't be the same person.

Configuration method

Previous: Smarty uses an php constant named 'SMARTY_DIR' as its system library directory. Basically, if your application can find the Smarty. class. php file, you don't need to set SMARTY_DIR, Smarty will work on its own. However, if Smarty. class. php is not in your include_path (one setting in php. ini), or if its absolute path is not set in your application, you must manually configure SMARTY_DIR (as most programs do). SMARTY_DIR must include a trailing slash ('/').

Text: Download the smarty compressed file, unzip to the php website root directory, you can look at the demo folder in advance, it is highly recommended that you set up a single 1 directory for each application using smarty (like the demo file structure in Smarty installation package)! And create cache (cache file), template (template directory), template_c (directory after template compilation) under smarty and directory, and create one example. php file. The contents of example. php are as follows:


<?php
// Introduce smarty Core class file 
require_once("./libs/Smarty.class.php");
// Instantiation smarty Object 
$smarty = new Smarty();
// Set the label identity of the template 
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
// Setting variables and values 
$smarty->assign('helloworld',10000);
// Reference template file 
$smarty->display('example.tpl');

After the code is written, create example. tpl file under template file and write < {$helloworld} > . Finally, open example. php in the browser, and 10000 will be parsed.

More readers interested in Smarty can check the topic of this site: smarty template introduction basic tutorial, PHP template technology summary, PHP database operation skills summary based on pdo, PHP operation and operator usage summary, PHP network programming skills summary, PHP basic syntax introduction tutorial, php object-oriented programming introduction tutorial, php string (string) usage summary, php+mysql database operation introduction tutorial and php common database operation skills summary

I hope this article is helpful to PHP programming based on smarty template.


Related articles: