Initial use and Considerations for PHP Smarty Framework

Source: Internet
Author: User
Tags php mysql smarty template
Initial use and Considerations for PHP Smarty Framework

1. What is a template engine
Two parts more concerned
1.1 is GUI (view, interface)--html CSS javascripte
1.2 is the business logic (PHP code)--php MYSQL

The template engine is a project developed using PHP

2.Smarty
2.1 Installation
1. Unzip, only use the Libs directory, need to use Smarty.class.php and plugins folder
2. Create folder: Templates and Template_c folder (default folder name)
3. Create a PHP file (see example)
Include "./libs/smarty.class.php";
Set the replacement content, set the display template
4. Access
2.2Smarty initialization
1. Initialization can modify the set value in Smarty.class.php
2. Initialize the PHP page when it is called
Problem solved: Warning:strftime () [Function.strftime]:
Date_default_timezone_set ("Asia/shanghai");
Include "./libs/smarty.class.php";
$TPL = new Smarty ();
Smarty Initialization
$tpl->template_dir= "./templates/";
$tpl->compile_dir= "./template_c/";
$TPL->left_delimiter= " ";

2.3Smarty Precautions for use
1. Find Resources (Css/js/image)
Resource files are placed in the corresponding resource location on the PHP page accessed (because the template is included in the PHP file when accessed)
2. When all display templates (or include) are specified, specify the base path in the Smarty template

3. When PHP references a smarty file outside the template directory, replace the Smarty initial file with an absolute path

Example code:

init.smarty.php

 
  Template_dir=root. ". /templates/"; $tpl->compile_dir=root." /template_c/"; $tpl->left_delimiter=" "
 
   ;? >


mysmarty.php

 
  Assign ("title", $title); $tpl->assign ("content", $content);//template file name can be arbitrarily defined: For example: MYSMARTY.TPL content is only HTML can be $tpl-> Display ("mysmarty.html");? >


Mysmarty.html

 
  <!--{$title}-->
 
  
  • 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.