tmdphp template engine Use tutorial _php template

Source: Internet
Author: User
Tags php code php foreach php template
In the PHP world to talk about template engine, must not be free to take smarty surgery,
This incredibly stupid template engine with a little bit of official color,
If there is no one like me, the rich sense of justice and innovative spirit of the young people come out,
Do not know it will continue to poison how many of those in the flowering season and to php full of beautiful fantasies of the teenager.
1. Grammar
Do you really think art has learned the syntax of {foreach Key=key item=item from= $contact}
But I can't learn <?php foreach ($contact as $key => $item) {?>?
{if $name eq ' Fred ' or $name eq ' Wilma '}
than <?php if ($name = = ' Fred ' or $name = ' Wilma ') {?> excellent where to go?
First of all, I have always been skeptical about the American Union's Learning Smarty Grammar, at least I haven't met a smarty grammar in my work for so many years.
And even if the art is willing to learn, why don't you teach him the authentic PHP grammar, but to teach him a door even you do not know the "Smarty language"
2. Visualization
When the page is passed from the art to your hand, then you give the perfect page, put on the disgusting smarty code,
And then in Dreamweaver, do you seriously see how ugly those pages have become,
Can you see the picture? Is the CSS still there? let alone include. And the time to revise it? Can you recognize it at a glance?
These are not solved, those so-called template engine how to match the "strong" word?
3...
More I don't say, here just take smarty for example, should not be difficult to find, other template engines are similar,
are busy inventing their own template language, and the real problem to be solved is to avoid it.
Now do you understand that the so-called template engine, the so-called powerful, are all TMD liars,
In the dead of night, I woke up countless times and felt that my burden was heavier, just because I could not tell you the cruel truth.
So I bitterly, pain am, busy schedule to write this name for the tmd_tpl of the real template engine,
Although it may not be strong now, but strong is the future of a certain.
TMD_TPL using the Getting Started Tutorial:
Next we'll learn how to use TMD_TPL, and there's not much difference between the process and the other template engines.
First, initialize the template engine
Copy Code code as follows:

<?php
To include TMD_TPL in
Require '.. /tmdphp/tmd_tpl.php '; Please change to the path where you TMD_TPL
Instantiation of TMD_TPL
$TPL = new Tmd_tpl ();
Here is the configuration Tmd_tpl
Specifies the template directory, ending with a slash
$TPL->tpl_dir = './tpl/';
Specify template file name extension
It is recommended to use PHP as a suffix, because the PHP code in Dreamweaver has a highlight effect.
Also in the Chrome browser can be opened directly to preview, with IE Open will be prompted to download.
$TPL->tpl_ext = '. tpl.php ';
Specify the Save directory for the compiled template
$TPL->cache_dir = './tpl_c/';
To set the validity period of a compiled file, in seconds
$TPL->cache_time = 0; 0 is recompiled every time,-1 is never expired,
Custom Regular Replace
$TPL->my_rep = Array (
' ~ (\.\./) +static/~ ' => '/proj-1/static/',
↑ If the access address of the project is http://localhost/proj-1/
Custom Replace there are a lot of tricks here, the entry period is not written first
);

Second, assign the value and display the page
Copy Code code as follows:

Normal assignment
$TPL->assign (' site_name ', ' Wang Daozhong strong flow ');
$TPL->assign (' Site_intro ', ' I'm a PHP programmer, Tmd_tpl's author. ');
Support Array
$blog = Array (
' title ' => ' to the TMD smarty ',
' Content ' => ' before explaining how to use the TMD_TPL, let me first explain why the wheel was invented again.
So what are we going to do about the world's so-called PHP template engine?
In the PHP world to talk about template engine, must not be free to take smarty surgery,
This incredibly stupid template engine with a little bit of official color,
If there is no one like me, the rich sense of justice and innovative spirit of the young people come out,
Do not know it will continue to poison how many of those in the flowering season and to php full of beautiful fantasies of the teenager. ',
Only two-dimensional arrays are currently supported, and in general two-dimensional is enough.
' Info ' => Array (
' Addtime ' => ' 2012.3.11 ',
' Author ' => ' Wangzhongjiang ',
' Weibo ' => ' Http://t.qq.com/teeband ',
),
);
$TPL->assign (' blog ', $blog);
The template will show the loop output this array
$links = Array (
' Cloud-dwelling community ' => ' http://www.jb51.net ',
' Material world ' => ' http://sc.jb51.net/',
' Baidu ' => ' http://www.baidu.com/',
' URL navigation ' => ' http://www.hao123.com ',
' Can't hurt ' => ' http://www.3buqi.com/',
Hey ' => ' http://www.hei123.net/',
);
$TPL->assign (' links ', $links);
$TPL->display (' index ');

third, the directory structure of template static files


Iv. Template Articles

Copy code code as follows:
//Template call variable
<div id= "logo" >
<p>{$site _intro}</p>
</div>
//calling array

//Two D array
<a href=" {$blog. Info.weibo} "target = "_blank" >{$blog .info.author}</a>
//The basic functionality of these template engines is the same in TMD_TPL.
//But loops and judgments, the TMD_TPL view is directly in PHP code. There is no need to create a template language to implement.
<?php
foreach ($links as $name => $url) {
?>
<li><a href= "{$url}" target= "_blank" & Gt {$name}</a></li>
<?php
}
?>
//function, is a weakness for the current TMD_TPL.
//Does not support formatting such as {$blog. CONTENT|NL2BR}.
{: nl2br ($blog [' content ']}//Only
<?=NL2BR ($blog [' content '])?>//or so
//will be automatically converted to
<?ph P Echo nl2br ($blog [' content '])?>
//If you call a function that has no return value
{~print_r ($blog)}


The real innovation of TMD_TPL is the transformation of the path.
You can insert a picture directly in the Dreamweaver, introduce CSS, call JS, and include another page.
Copy Code code as follows:

Insert Picture
Introducing CSS
<link href= ". /static/style.css "rel=" stylesheet "type=" Text/css "media=" "Screen"/>
Call JS
<script type= "Text/javascript" src= ". /static/test.js "></script>
Contains a page
<?php include (' inc/footer.tpl.php ');?>

• After using the TMD_TPL template engine

View through HTTP access effects > points here <

In the Dreamweaver (such a front-end personnel have a way ~)

In Chrome (only include pages cannot be displayed)

• Without TMD_TPL, let's look at the discuz! and dedecms templates.

discuz!

Dedecms

Now you know how ridiculous the so-called powerful template engines are?

What are you waiting for? It's time to change history, click your mouse, download the second generation PHP template engine tmd_tpl!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.