Before explaining how to use tmd_tpl, I want to explain why I want to re-invent the wheel. Let's start with what contributions the so-called PHP template engine has made to everyone in this world.
Before explaining how to use tmd_tpl, I want to explain why I want to re-invent the wheel. Let's start with what contributions the so-called PHP template engine has made to everyone in this world.
When talking about the template engine in the PHP field, you must take the Smarty to open the knife,
This silly template engine with a little bit of official colors,
Without a young man like me with a sense of justice and innovative spirit,
I don't know how much it will continue to poison teenagers who are in the flower season and are full of beautiful fantasies about PHP.
1. Syntax
You really think that the {foreach key = key item = item from = $ contact} syntax is beautiful.
But cannot learn $ Item) {?> ?
{If $ name eq "Fred" or $ name eq "Wilma "}
Youbi Where can I find excellence?
First of all, I have always been skeptical about the Smarty syntax I will learn. At least I have never met a Smarty syntax for so many years of work,
Even if the artist is willing to learn, why don't you teach him authentic PHP syntax? Instead, you need to teach him a "Smarty language" that you don't know"
2. Visualization
When the page is handed over from the artist to your hand, then you give the perfect web pages and put the disgusting Smarty code on them,
Then, in Dreamweaver, do you seriously read how ugly those pages have become,
Is the image still visible? Is CSS still there? Not to mention include. But what about modification? Can you still recognize it at a glance?
These cannot be solved. How can these so-called template engines be "powerful?
3 ....
If there are too many templates, I will not mention them. Here I just use Smarty as an example. It is not difficult to find that other template engines are similar,
All of them are busy inventing their own template language, while the problems that really need to be solved are avoided,
Do you understand that the so-called template engine is powerful and all are TMD scammers,
In the dark night, I woke up countless times and felt that my burden was heavier, just because I could not tell you this cruel fact.
So I was so worried that I took the time to write the real template engine named tmd_tpl,
Although it may not be powerful yet, it is a necessity for the future.
· Tmd _ tpl getting started Tutorial:
Next we will learn how to use tmd_tpl. The process is no different from other template engines.
I. initialize the template engine
The Code is as follows:
// Include tmd_tpl
Require '../tmdphp/tmd_tpl.php'; // change it to the path of your tmd_tpl.
// Instantiate tmd_tpl
$ TPL = new tmd_tpl ();
// Configure tmd_tpl
// Specify the template directory, ending with a slash
$ TPL-> tpl_dir = './tpl /';
// Specify the template file extension.
// We recommend that you use php as the suffix, because php code is highlighted in Dreamweaver.
// In addition, you can directly open it in the Chrome browser for preview. If you open it with IE, a prompt is displayed for download.
$ TPL-> tpl_ext = '. tpl. php ';
// Specify the directory for saving the compiled Template
$ TPL-> cache_dir = './tpl_c /';
// Set the validity period of the compiled file, in seconds
$ TPL-> cache_time = 0; // 0 is re-compiled every time, and-1 never expires,
// Custom Regular Expression replacement
$ TPL-> my_rep = array (
'~ (\. \./) + Static /~ '=>'/Proj-1/static /',
// Configure if the project's access address is http: // localhost/proj-1/
// There are a lot of tips for custom replacement, which will not be written during the getting-started period.
);
2. assign values and display the page
The Code is as follows:
// Normal value assignment
$ TPL-> assign ('site _ name', 'wangdao zhongqiang stream ');
$ TPL-> assign ('site _ intro', 'I am a PHP programmer and the author of tmd_tpl. ');
// Supports Arrays
$ Blog = array (
'Title' => 'smarty to TMD ',
'Content' => 'Before explaining how to use tmd_tpl, I want to explain why we need to re-invent the wheel.
Let's start with what contributions the so-called PHP template engine has made to everyone in this world.
When talking about the template engine in the PHP field, you must take the Smarty to open the knife,
This silly template engine with a little bit of official colors,
Without a young man like me with a sense of justice and innovative spirit,
I don't know how much it will continue to poison teenagers who are in the flower season and are full of beautiful fantasies about PHP. ',
// Currently, only two-dimensional arrays are supported. Generally, two-dimensional arrays are sufficient.
'Info' => array (
'Addtime' => '2017. 123 ',
'Author' => 'wang zhongqiang ',
'Weibo '=> 'HTTP: // t.qq.com/teeband ',
),
);
$ TPL-> assign ('blog ', $ blog );
// This array is output cyclically in the template.
$ Links = array (
'Feet home' => 'HTTP: // www.jb51.net ',
'Material world' => 'HTTP: // SC .jb51.net /',
'Baidu '=> 'HTTP: // www.baidu.com /',
'Url navigation '=> 'HTTP: // www.hao123.com ',
'Injury incom' => 'HTTP: // www.3buqi.com /',
'Hey! '=> 'HTTP: // www.hei123.net /',
);
$ TPL-> assign ('links ', $ links );
$ TPL-> display ('index ');
Iii. directory structure of static template files
Iv. templates
The Code is as follows:
// Call variables in the template
{$ Site_name}
{$ Site_intro}
// Call the Array
{$ Blog. title}
// Two-dimensional array
{$ Blog.info. author}
// The basic functions of these template engines are the same in tmd_tpl.
// But for loop and judgment, tmd_tpl uses php Code directly. There is no need to create a template language for implementation.
Foreach ($ links as $ name => $ url ){
?>
{$ Name}
}
?>
// For functions, tmd_tpl is a weakness.
// The format {$ blog. content | nl2br} is not supported yet.
{: Nl2br ($ blog ['content'])} // only
// Or
// Both are automatically converted
// If you call a function that does not return a value
{~ Print_r ($ blog )}
The true innovation of tmd_tpl lies in path conversion.
You can insert images directly in Dreamweaver, introduce CSS, call JS, and include another page.
The Code is as follows:
// Insert an image
// Introduce CSS
// Call JS