PHP Classes

File: btsample.php

Recommend this page to a friend!
  Classes of Jonathan Gotti  >  Block template  >  btsample.php  >  Download  
File: btsample.php
Role: Example script
Content type: text/plain
Description: sample of use
Class: Block template
Template engine based in the concept of blocks
Author: By
Last change:
Date: 11 years ago
Size: 2,143 bytes


Class file image Download
basic Sample of use for block_template
templates are in ./template directory

# include the class file

$page_title = 'TEST PAGE';
$template_name = 'default';

# instantiate template parser, doing this the file template/default/template.php will be read
# and if a template/default/css.css exist then it will be automaticaly added
$page = &new block_template($page_title,$template_name);

# you can add an alternate stylesheet like this
# or add css rules in the header (<style></style>) like this
$page->add_css('a:hover {color:red;}');
  .header {color:red;font-size:24px;text-lign:center;}
  .menu {float:left;background:silver;color:navy;}
  .box {border:solid silver 1px;display:table;margin:15px;}
  .title{position:relative;TOP:-20px;border:dashed silver 1px;background:white;display:table;padding:0 10px 0 10px;font-size:16px;}
# you can add javascript file or function in the same ways using add_js() method
# or even a favicon by using add_favicon.
# If you want you can add some meta
$page->add_meta("page description",'description');

# Now the interesting stuff:
#create a menu:
$menuentrys .= $page->templatize(array('url'=>'bttest.php','label'=>"menu entry $i"),'MENU_ENTRY');
$menu = $page->add_templatize_content(array('menuentrys'=>$menuentrys),'MENU');

# now add some boxed content (see related method for more details)
$page->add_box_content('here your box content','box title');

# add some news
$news .= $page->templatize(array('url'=>'bttest.php','intro'=>"intro for news $i, just an intro at all!",'title'=>"$i title"),'NEWS_INTROS');
$news = $page->templatize(array('newscontent'=>$news),'NEWS_BOX');

# and then render the page (you can save it to a file and manage a cache if you want)
$page->output(array('title'=>'Block Template TEST PAGE'));