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!

DependencyInjection(DI)inPHPenhancescodeflexibilityandtestabilitybydecouplingdependencycreationfromusage.ToimplementDIeffectively:1)UseDIcontainersjudiciouslytoavoidover-engineering.2)Avoidconstructoroverloadbylimitingdependenciestothreeorfour.3)Adhe

ToimproveyourPHPwebsite'sperformance,usethesestrategies:1)ImplementopcodecachingwithOPcachetospeedupscriptinterpretation.2)Optimizedatabasequeriesbyselectingonlynecessaryfields.3)UsecachingsystemslikeRedisorMemcachedtoreducedatabaseload.4)Applyasynch

Yes,itispossibletosendmassemailswithPHP.1)UselibrarieslikePHPMailerorSwiftMailerforefficientemailsending.2)Implementdelaysbetweenemailstoavoidspamflags.3)Personalizeemailsusingdynamiccontenttoimproveengagement.4)UsequeuesystemslikeRabbitMQorRedisforb

DependencyInjection(DI)inPHPisadesignpatternthatachievesInversionofControl(IoC)byallowingdependenciestobeinjectedintoclasses,enhancingmodularity,testability,andflexibility.DIdecouplesclassesfromspecificimplementations,makingcodemoremanageableandadapt

The best ways to send emails using PHP include: 1. Use PHP's mail() function to basic sending; 2. Use PHPMailer library to send more complex HTML mail; 3. Use transactional mail services such as SendGrid to improve reliability and analysis capabilities. With these methods, you can ensure that emails not only reach the inbox, but also attract recipients.

Calculating the total number of elements in a PHP multidimensional array can be done using recursive or iterative methods. 1. The recursive method counts by traversing the array and recursively processing nested arrays. 2. The iterative method uses the stack to simulate recursion to avoid depth problems. 3. The array_walk_recursive function can also be implemented, but it requires manual counting.

In PHP, the characteristic of a do-while loop is to ensure that the loop body is executed at least once, and then decide whether to continue the loop based on the conditions. 1) It executes the loop body before conditional checking, suitable for scenarios where operations need to be performed at least once, such as user input verification and menu systems. 2) However, the syntax of the do-while loop can cause confusion among newbies and may add unnecessary performance overhead.

Efficient hashing strings in PHP can use the following methods: 1. Use the md5 function for fast hashing, but is not suitable for password storage. 2. Use the sha256 function to improve security. 3. Use the password_hash function to process passwords to provide the highest security and convenience.


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

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!
