tmdphp template engine Use tutorial _php tutorial

Source: Internet
Author: User
In the PHP community to talk about the template engine, it is necessary to take smarty surgery,
This incredibly stupid but with a little official color of the template engine,
If there is no such person with a sense of justice and creative spirit passionate young people stand out,
I do not know if it will continue to poison how many of those in the flowering and full of beautiful fantasy of PHP young.
1. Syntax
Do you really think that the art of learning {foreach Key=key item=item from= $contact} syntax like this
But I can't learn. $item) {?>?
and {if $name eq "Fred" or $name eq "Wilma"}
and more than Where is the best way to go?
First of all, I have always been skeptical about the Smarty Grammar of American Union studies, at least I have not met a smarty grammar for so many years.
And even if the art is willing to learn, why don't you teach him the authentic PHP syntax, but teach him a "smarty language" that you don't know.
2. Visualization
When the page is handed over from the artwork to your hand, then you give the perfect Web page with that disgusting smarty code,
And in Dreamweaver, are you seriously looking at how ugly those pages have become,
Can you see the picture? Is the CSS still there? Let alone the include. And the time to change it? Can you recognize it at a glance?
None of this solves, how can those so-called template engines match the word "mighty"?
3 .....
More I will not say, here is just take smarty for example, it should be easy to find that other template engine is similar,
are busy inventing their own template language, and the problem that really needs to be solved is to be avoided,
Now do you understand that the so-called template engine, the so-called powerful, are TMD liars,
In the dead of night, I woke up countless times, feeling that my burdens were heavier, just because I could not tell you this cruel fact.
So I bitterly, pain am, busy time to write the name of the tmd_tpl of the real template engine,
Though it may not be strong yet, strength is a necessity for the future.
TMD_TPL How to use the Getting Started tutorial:
Next, we will learn how to use TMD_TPL, and there is not much difference between the process and other template engines.
First, initialize the template engine
Copy CodeThe code is as follows:
Include TMD_TPL in the
Require '. /tmdphp/tmd_tpl.php '; Please change the path of your TMD_TPL
Instantiate 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 this makes the PHP code in Dreamweaver have a bright effect.
In addition, in the Chrome browser can be opened directly to preview, open with IE prompts to download.
$TPL->tpl_ext = '. tpl.php ';
Specify the Save directory for the post-compilation template
$TPL->cache_dir = './tpl_c/';
Set the validity period of the compiled file, in seconds
$TPL->cache_time = 0; 0 is recompiled every time,-1 is never expired,
Custom regular substitution
$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, and the entry period is not written.
);

Second, assign and display the page
Copy CodeThe code is as follows:
Normal assignment
$TPL->assign (' site_name ', ' Paramount strong Flow ');
$TPL->assign (' Site_intro ', ' I am a PHP programmer, author of Tmd_tpl. ');
Support arrays
$blog = Array (
' title ' = ' Go to TMD's Smarty ',
' content ' and ' = ' before I explain how to use the TMD_TPL, I want to talk about why we should reinvent the wheel.
Let's start with what the so-called PHP template engine in the world has done for everyone.
In the PHP community to talk about the template engine, it is necessary to take smarty surgery,
This incredibly stupid but with a little official color of the template engine,
If there is no such person with a sense of justice and creative spirit passionate young people stand out,
I do not know if it will continue to poison how many of those in the flowering and full of beautiful fantasy of PHP young. ',
Currently, only two-dimensional arrays are supported, in general, two dimensions are sufficient.
' 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 (
' The home of the script ' = ' 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 ' = ' and ' http://www.hei123.net/',
);
$TPL->assign (' links ', $links);
$TPL->display (' index ');

III. directory structure of template static files


Four, the template article
Copy the Code code as follows:
Calling Variables in templates

{$site _name}


{$site _intro}



Call Array

{$blog. Title}


Two-dimensional arrays
{$blog. Info.author}
The basic functionality of these template engines is the same in TMD_TPL.
But looping and judging, tmd_tpl view is directly in PHP code. There is no need to create a template language to implement.
foreach ($links as $name = = $url) {
?>
  • {$name}

  • }
    ?>
    function, for the current TMD_TPL, is a weakness.
    {$blog. CONTENT|NL2BR} is not supported in this format.
    {: NL2BR ($blog [' content '])}//Only this
    Or so
    are automatically converted to

    If you call a function that has no return value
    {~print_r ($blog)}

    The real innovation of TMD_TPL is the transformation of paths.
    You can insert images directly into Dreamweaver, introduce CSS, Invoke JS, and include another page.
    Copy CodeThe code is as follows:
    Insert Picture

    Introducing CSS

    Call JS

    Contains a page


    • After using the TMD_TPL template engine

    View the effects > points by HTTP access here <

    In Dreamweaver (so the front-end people have a way to do it ~)

    In Chrome (only the Include page cannot be displayed)

    • Without TMD_TPL, let's take a look at the templates of discuz! and Dedecms.

    discuz!

    Dedecms

    Now you know how ridiculous those so-called powerful templating engines are?

    What are you waiting for? Time to change the history, click on your mouse, download the second generation PHP template engine tmd_tpl!

    http://www.bkjia.com/PHPjc/325247.html www.bkjia.com true http://www.bkjia.com/PHPjc/325247.html techarticle in the PHP world to talk about the template engine, it is necessary to take the smarty, this incredibly stupid but with a little official color of the template engine, if not me so people rich sense of justice and rich ...

  • 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.