PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Sebastian Potasiak   Separated Template   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example of using class
Class: Separated Template
Process HTML templates using CSS classes
Author: By
Last change: Updated to latest version (2.1)
Date: 14 years ago
Size: 1,132 bytes
 

Contents

Class file image Download
<?php
include('sTemplate.class.php');

$tpl = new sTemplate;

$tpl->dir = './templates/'; // Use only if you have another directory name - this is default
$tpl->ext = '.html'; // Like dir - use if you have another
$tpl->atr = 'class'; // Like dir and ext - use if you want to use another attribute in html

// Create an array with variables
$data = array(
   
"title" => "Latest News",
   
"news" => array(
        array(
           
"header" => "My first news",
           
"description" => "This is description for my first news"
       
),
         array(
           
"header" => "Second information of the day",
           
"description" => "Some text, description, etc."
       
),
         array(
           
"header" => "My third news",
           
"description" => "This is description for my 3rd news"
       
)

    )
);

// Show parsed template
$tpl->parse("main", $data);

// Also you can use function load(), like in previous version
$tpl->load("main", $data, true);

// Difference between parse() and load():
// parse() third attribute $show_result = true, in load() it's false
?>