• home
  • forum
  • my
  • kt
  • download
  • Tips of PhpLib

    Author: 2008-08-28 07:11:31 From:

    The pHpLib template is very easy to develop a website.The pHpLib basically based on a template class. which have only five function are used to differ the php code from html code.

    The template class allows you to keep your HTML code in some external files which are completely free of PHP code, but contain replacement fields. The class provides you with functions which can fill in the replacement fields with arbitrary strings.

    Firstly we create a object o template class.
    <php
    include('template.php');
    $tpl=new Template();
    >

    The following function are mostly used in pHpLib
    1. set_file
    2. set_block
    3. set_var
    4. parse

    1. set_file
    This is basically use for set a file tpl.html file.It has two parameters one is handle another one is path+filename. where we write the html code combined with tempate variables and blocks.
    synatx
    set_file('file_handle', path+filename);
    example
    $templatePath ='/home/'
    $tpl->set_file('template',$templatePath .'test.tpl.htm');

    2. set_block
    This is basically use for looping and conditional logic in html. we set a block means that inner part of block moving like for loop and condtion like if. This is must combined use with parse and set_var function.
    synatx
    set_block('file_handle','block_name','block_handle')

    eg
    $tpl->set_block('template','TPL_SHOW_DATA_BLK','HAN_SHOW_DATA_BLK');

    3. set_var
    This is used to set a php variable to template based variable.which used in template file.
    In php we define a variable with $ sign. In php lib we use {} for a variable.
    eg.
    Php variable $flag
    template Variable TPL_VAR_FLAG

    synatx
    set_var('template_variable_name',php_variable_name);
    eg
    $tpl->set_var('TPL_VAR_FLAG',$flag);

    4. parse
    This is basically used to parse a block and parse a file.It replace template_variable_name and blocks to corresponding htmlcode.
    it has three parameters block handle,block name,true/false
    if true, the substituted variables are appended to $target otherwise the existing value of $target is replaced

    parse('block_handle','block_name',true/false);

    eg.
    $tpl->parse('HAN_SHOW_DATA_BLK','TPL_SHOW_DATA_BLK',true);

    example 1

    <php
    include('template.php');
    $tpl=new Template();
    $templatePath ='/home/'
    $tpl->set_file('template',$templatePath .'test.tpl.htm');
    $tpl->set_block('template','TPL_SHOW_DATA_BLK','HAN_SHOW_DATA_BLK');
    if($flag){
    $tpl->set_var('TPL_VAR_FLAG',$flag);
    $tpl->parse('HAN_SHOW_DATA_BLK','TPL_SHOW_DATA_BLK',true);
    }else{
    $tpl->set_var('HAN_SHOW_DATA_BLK','');
    }
    >

    html code

    <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    <html>
    <head>
    <title> new document </head>
    <body>
    <!-- BEGIN TPL_SHOW_DATA_BLK -->
    {TPL_VAR_FLAG}
    <!-- BEGIN TPL_SHOW_DATA_BLK -->
    </body>
    <html>

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (17)
      Discussion Boards (8)
      E Commerce (8)
      Email Systems (13)
      Error Handling (7)
      File Manipulation (24)
      Flash and PHP (6)
      Form Processing (19)
      Guestbooks (12)
      Image Manipulation (21)
      Installing PHP (7)
      Introduction to PHP (23)
      Link Indexing (8)
      Mailing List Management (9)
      Miscellaneous (53)
      Networking (8)
      News Publishing (9)
      OOP (24)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (6)
      Postcards (1)
      Randomizing (14)
      Redirection (11)
      Searching (9)
      Security (29)
      Site Navigation (16)
      User Authentication (14)
      WAP and WML (7)
      Web Fetching (8)
      Web Traffic Analysis (15)
      XML and PHP (16)

    New

    Hot