LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-19-2010, 05:39 AM   #1
delite
Member
 
Registered: Nov 2008
Posts: 44

Rep: Reputation: 15
PHP Templating


Hi, i'm working on a small CMS project. When starting out I didn't know too much CSS, so virtually everything was wrapped in HTML and a little CSS. The main page templates used the following functions:

Code:
function theme_stylise($data,$tpl='node')
{
	global $theme_blocks;
	return theme_evaluate($theme_blocks[$tpl],$data);
}

function theme_evaluate($s,$data=array())
{
	global $page;
	ob_start();
	$x=@eval("?>".$s);
	$l=ob_get_contents();
	ob_end_clean();
	return $l;
}


// EXAMPLE TEMPLATES

$theme_blocks['login_user']="<div class='login_user'><?php print \$data['content']; ?></div>";

$theme_blocks['profile_menu']="<div class='profile_menu'><?php print ' | '; foreach(\$data['menu'] as \$e){ print \$e.' | ';} ?></div>";

Further down the line I also added the following:

Code:
list($tmp_list,$tmp_node)=shop_templates('delivery');
$_SHIPPING_.=replace_all($tmp_list,array($_SHIPPING_ITEMS_,$_SHIPPING_DEST_,$_SHIPPING_TITLE_),$tmp_node);


// EXAMPLE TEMPLATES

function shop_templates($ref,$type=0)
{
	if($ref=="invoice"){
		$s="
		<h2>Order Reference:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_ORDER_REF_</h2><br />
		<h2>Order Details</h2><table><tr class='tr_pch'><td><b>Status</b></td><td><b>Order Ref</b></td><td><b>Date</b></td><td><b>Total Cost</b></td></tr>
		<tr><td colspan='99'><hr /></td></tr>
		<tr class='tr_pc1'><td>_ORDER_STATUS__ORDER_RESEND_</td><td>_ORDER_REF_</td><td>_ORDER_DATE_</td><td>_ORDER_TOTAL_</td></tr>
		<tr><td colspan='99'><hr /></td></tr>
		</table>
		<br /><br />
		
		<h2>Order Items</h2>
		<table>
		<tr class='tr_pch'><td><b>Status</b></td><td><b>Title</b></td><td><b>Ref</b></td><td><b>Qty.</b></td><td><b>Items Cost</b></td><td><b>Shipping</b></td><td><b>Total</b></td></tr>
		<tr><td colspan='99'><hr /></td></tr>
		_INVOICE_ITEMS_
		<!--<tr><td colspan='99'><br /><hr /><br /></td></tr>-->
		</table><br />
		";
		
		return array(array("_ORDER_STATUS_","_ORDER_RESEND_","_ORDER_REF_","_ORDER_DATE_","_ORDER_TOTAL_","_INVOICE_ITEMS_"),$s);
	}
	elseif($ref=="invoice_item"){
		$s="<tr class='_ODD_'><td>_STATUS_</td><td>_ITEM_TITLE_</td><td>_ITEM_REF_</td><td>_QTY_</td><td>_ITEM_COST_</td><td>_SHIP_TITLE_ _SHIP_COST_</td><td>_TOTAL_</td></tr>\n";
		$s.="<tr class='_ODD_'><td colspan='7'>_DROPBOX_</td></tr>\n";
		$s.="<tr><td colspan='7'><hr /></td></tr>\n";
		return array(array("_ODD_","_STATUS_","_ITEM_TITLE_","_ITEM_REF_","_QTY_","_ITEM_COST_","_SHIP_TITLE_","_SHIP_COST_","_TOTAL_","_DROPBOX_"),$s);
	}
	elseif($ref=="size_item"){
		$s="<div class='shop_size_item'>_SIZE_RADIO_ _SIZE_TITLE_ : _SIZE_COST_ - _SIZE_DESC_</div>";
		return array(array("_SIZE_RADIO_","_SIZE_TITLE_","_SIZE_DESC_","_SIZE_COST_"),$s);
	}
	return null;
}

Now most small page parts use the second method, and are then grouped together by the first method.

After implementing the second method in a single module I realised that it was being called quite a bit.

So before updating the rest of the CMS with this method I'd like to hear your views on efficiency, templating, either using either of the above methods, or any more you may suggest.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Installing Nginx With PHP 5.3 And PHP-FPM On Ubuntu Lucid Lynx (10.04) LXer Syndicated Linux News 0 06-15-2010 12:42 AM
LXer: Smarty templating and presentation library for PHP LXer Syndicated Linux News 0 12-09-2005 06:53 PM
LXer: Smarty templating and presentation library for PHP LXer Syndicated Linux News 0 12-09-2005 03:36 PM
Creating a PHP templating system - any ideas? vharishankar Programming 1 07-06-2005 11:51 PM
php apache or php cgi - php learner rblampain Linux - Security 3 12-18-2004 12:10 AM


All times are GMT -5. The time now is 05:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration