TMDPHP template engine usage tutorial_PHP tutorial
When talking about template engines in the PHP world, it is inevitable to start with Smarty.
This is an extremely silly but slightly official template engine.
If there were not people like me who have a sense of justice and innovative spirit, Passionate young people have come forward,
I don’t know how many young people it will continue to poison in their prime and who are full of beautiful fantasies about PHP.
1. Grammar
Do you really think that artists can learn {foreach key=key item=item from=$contact} such syntax
But they can’t learn$item) { ?>?
And {if $name eq "Fred" or $name eq "Wilma"}
is better thanFirst of all, I am always skeptical about artists learning Smarty syntax. At least I have never met anyone who knows Smarty syntax in so many years of working.
And even if an artist is willing to learn, why don’t you teach him authentic PHP? Grammar, but you have to teach him a "Smarty language" that you can't even understand yourself
2. Visualization
When the page is handed over from the artist to you, then you add that disgusting look to those perfect web pages Smarty code,
Then in Dreamweaver, have you seriously looked at how ugly those pages have become?
Can the pictures still be visible? Is CSS still around? Not to mention include. And what about when it’s time to make changes? Can you still recognize it at a glance?
If these cannot be solved, how can those so-called template engines be worthy of the word "powerful"?
3....
I won’t go into too much detail. I’m just taking Smarty as an example. It should not be difficult to find that other template engines are similar.
They are all busy inventing their own template languages. The problems that really need to be solved are avoided.
Do you understand now that the so-called template engine and the so-called power are all liars?
In the dead of night, I woke up countless times, I feel like my burden is heavier just because I can't tell you this cruel fact.
So I was heartbroken and heartbroken, and took time out of my busy schedule to write this real template engine named tmd_tpl.
Although it may not be powerful now, being powerful is a necessity in the future.
·Introductory tutorial on using tmd_tpl:
Next, let’s learn how to use tmd_tpl. The process is not much different from other template engines.
1. Initialize the template engine
//Include tmd_tpl
require '../tmdphp/tmd_tpl.php'; // Please change to the path where your tmd_tpl is located
// Instantiate tmd_tpl
$TPL = new tmd_tpl ();
// The following is the configuration of tmd_tpl
// Specify the template directory, ending with a slash
$TPL->tpl_dir = './tpl/';
// Specify the template file Extension
// It is recommended to use php as the suffix, because this will have a highlighting effect on the php code in Dreamweaver.
// In addition, you can open it directly in the Chrome browser for preview, and you will be prompted to download when opening it in IE.
$TPL->tpl_ext = '.tpl.php';
// Specify the directory where the compiled template is saved
$TPL->cache_dir = './tpl_c/';
/ / Set the validity period of the compiled file, unit: seconds
$TPL->cache_time = 0; // 0 means recompile every time, -1 means never expires,
// Custom regular replacement
$TPL->my_rep = array(
'~(../)+static/~' => '/proj-1/static/',
// ↑If the access address of the project It is http://localhost/proj-1/
// There are many techniques for custom replacement. I won’t write them down for the entry-level period
);
2. Assignment And display the page
// Ordinary assignment
$TPL->assign('site_name', '王道中强流');
$TPL->assign('site_intro', 'I am a PHP programmer, author of tmd_tpl. ');
// Supports arrays
$blog = array(
'title' => 'Go to TMD's Smarty',
'content' => ; 'Before explaining how to use tmd_tpl, I want to first talk about why we need to reinvent the wheel.
Then let’s start with what contributions the so-called PHP template engines in the world have made for everyone.
When talking about template engines in the PHP world, it is inevitable to start with Smarty.
This is an extremely silly but slightly official template engine.
If there were not people like me who have a sense of justice and innovative spirit, Passionate young people have come forward,
I don’t know how many young people in their prime and full of beautiful fantasies about PHP will continue to be poisoned by it. ',
// Currently, it only supports two-dimensional arrays, generally speaking, two-dimensional arrays. It's enough
'info' => array(
'addtime' => '2012.3.11',
'author' => 'Wang Zhongqiang',
'weibo' => ; 'http://t.qq.com/teeband',
),
);
$TPL->assign('blog', $blog);
// in template Loop the demonstration to output this array
$links = array(
'Script Home' => 'http://www.jb51.net',
'Material World' => 'http: //sc.jb51.net/',
'Baidu' => 'http://www.baidu.com/',
'Website navigation' => 'http://www.hao123 .com',
'Can't afford to be hurt' => 'http://www.3buqi.com/',
'Hey! ' => 'http://www.hei123.net/' ,
);
$TPL->assign('links', $links);
$TPL->display('index');
3. Directory structure of template static files
4. Template
// Call variables in the template
// Call array
{$blog.title}
// Two-dimensional array
{$blog.info.author}
// The basic functions of these template engines are also the same in tmd_tpl.
// But for looping and judgment, the tmd_tpl view is to use PHP code directly. There is no need to create a template language to do this.
foreach ($links as $name => $url) {
?>
}
?>
// In terms of functions, for the current tmd_tpl , is a weakness.
// The format {$blog.content|nl2br} is not supported yet.
{:nl2br( $blog['content'] )} // This is the only way
=nl2br( $blog['content'] )?> // Or this
// will be automatically converted to
// If some functions without return values are called
{~print_r( $blog )}
The real innovation of tmd_tpl lies in the conversion of paths.
You can insert images directly in Dreamweaver, introduce CSS, call JS, and include another page.
// Insert picture

// Introduce CSS
// Call JS
// Include a page
·After using tmd_tpl template engine
View the effect of access via http >Click here<
In Dreamweaver (this is how the front-end staff can do it~)
In Chrome (only included pages cannot be displayed)
·If tmd_tpl is not used, let’s take a look at the templates of Discuz! and DedeCMS.
Discuz!
DedeCms
Now you know how ridiculous those so-called powerful template engines are, right?
What are you waiting for? The time to change history has arrived, click the mouse in your hand and download the second-generation PHP template engine tmd_tpl!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

Laravel optimizes the web development process including: 1. Use the routing system to manage the URL structure; 2. Use the Blade template engine to simplify view development; 3. Handle time-consuming tasks through queues; 4. Use EloquentORM to simplify database operations; 5. Follow best practices to improve code quality and maintainability.
