Smarty Quick START II _php Tutorial

Source: Internet
Author: User
Tags smarty template
In order to more convenient use Smarty later, we can "load Smarty template engine", "Establish Smarty object", "Set parameters of Smarty object" Three steps into a common PHP file, in the future where we need to use the place we directly reuqire, you can, For example:

1. Establish a main.php

Include smarty/smarty.class.php;
The next time you migrate, you only need to change the root pointing location ~
Const DIR_SEP = directory_separator;
Define (ROOT, D:. Dir_sep._php_test.dir_sep. TEST2.DIR_SEP); $TPL = new Smarty ();
$tpl->template_dir = ROOT.templates.DIR_SEP;
$tpl->complie_dir = ROOT.templates_c.DIR_SEP;
$tpl->config_dir = ROOT.configs.DIR_SEP;
$tpl->cache_dir = ROOT.cache.DIR_SEP;
$tpl->left_delimiter = <{;
$tpl->right_delimiter =}>;
?>

Note 1: Why use directory_separator here? (Click to view)

Note 2:left_delimiter and Right_delimiter are left and right terminator variables, which can be defined here as other strings (the default is {}).

2. Under Templates, create a new test.htm




<{$title}>


<{$content}>

3. Call the template page to populate the title and content with a new test_smarty_1.php

Require main.php;
$tpl->assign (title, New Message);
$tpl->assign (content, this is Test smarty!);
$tpl->display (test.htm);
?>

Can also be written like this

Require main.php;
$TPL->assign (Array (title=>newmessage, Content=>this is Test smarty!));
$tpl->display (test.htm);
?>

Output Result:

Page Title display: Newmessage

Page content display: This is Test smarty!

http://www.bkjia.com/PHPjc/478801.html www.bkjia.com true http://www.bkjia.com/PHPjc/478801.html techarticle in order to use Smarty more conveniently later, we can put "load Smarty template engine", "Establish Smarty object", "Set parameters of Smarty object" Three steps to a public ...

  • Related Article

    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.