phpfluxlib template engine

phpfluxlib template engine :: Documentation

Introduction

The phpfluxlib template engine consists of several logically separated elements, glued together using a simple centralized XML configuration file (or several). It is based in the Tiles library, a plugin for Jakarta Struts.

Templates are an agregation of layouts and blocks that are called programaticly to present a page. A template can inherit data (blocks and the layout) from another template, hierarquicly.

Layouts are a simple php script that define the structure of the layout, placing the blocks inside the design. They can define static named blocks, like 'header' and 'footer', or more dynamic, for example, receiving a list of blocks and iterating them in a column fashion, implementing a dinamic columned layout.

Blocks provide the website content. They can be any file that can be included through 'include()' or values like:

  • static HTML
  • PHP scripts
  • Strings
  • Another template (providing greater abstraction possibilities)
Blocks can receive data programaticly, before calling the layout, and provide reusability through abstraction.

Properties

Properties are defined in the configuration XML file and provide global configuration variables throughout the website and also inside the XML config file.

Templates


<template name="baseLayout" layout="${LayoutDir}/siteLayout.tpl.php">
	<block name="title" type="string" value="${TituloSite}" />
	<block name="header" type="page" value="${BlocksDir}/common/header.php" />
	<block name="footer" type="page" value="${BlocksDir}/common/footer.php" />
	<block name="GoogleAnalyticsTracker" type="page" value="${BlocksDir}/googleAnalytics.php" />
	<block name="menu" type="template" value="comum.menu" />
</template>

Layouts



<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=<?= $tpl->getProperty('GlobalCharset');?>">
	<title><? $tpl->putBlock('title');?></title>
	<link rel="stylesheet" href="css/style.css">
</head>
<body >
	<table cellspacing="0" cellpading="0" class="main center" align="center">
		<tr>
			<td class="header"><? $tpl->putBlock('header');?></td>
		</tr>
		<tr>
			<td class=""><? $tpl->putBlock("menu"); ?></td>
		</tr>
		<tr>
			<td class="title"><? $tpl->putBlock('title');?></td>
		</tr>
		<tr>
			<td class="content"><? $tpl->putBlock('content');?></td>
		</tr>
		<tr>
			<td class="footer"><? $tpl->putBlock('footer');?></td>
		</tr>
	</table>
	<? $tpl->putBlock('GoogleAnalyticsTracker');?>
</body>
</html>


Blocks



<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "<?= $tpl->getProperty('GoogleAnalytics_uacct');?>"
urchinTracker();
</script>