
This example shows how to use inheritance.
<?php
$apptitle = 'MyPage'; // Application title
$pages = array('home', 'about', 'contact'); // List of available pages
$page = 'home'; // Default page
require_once('templum.php');
$templum = new Templum('view', compact('apptitle'));
if (array_key_exists('page', $_GET) && in_array($_GET['page'], $pages)) {
$page = $_GET['page'];
}
$tpl = $templum->template($page);
print($tpl->render());
?>
[[ $this->inherit('index') ]]
[: block page :]About[: endblock :]
[: block contents :]
This page is about {{ $apptitle }}. {{ $apptitle }} is an example of inheritance in the Templum templating library for PHP.
[: endblock :]
[[ $this->inherit('index') ]]
[: block page :]Home[: endblock :]
[: block contents :]
This is the homepage of the {{ $apptitle }} example.
[: endblock :]
[[ $this->inherit('index') ]]
[: block page :]Contact[: endblock :]
[: block contents :]
If you need to contact us, please email to <a href="mailto:some@example.com">some@example.com</a>.
[: endblock :]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>{{ $apptitle }} - [: block page :]Index[: endblock :]</title>
<style>
body { margin: 0px; padding: 0px; }
h1 { color: #6090F0; background-color: #404040; padding: 10px; margin: 0px; }
h2 { color: #303030; margin-left: 30px; }
div#menu { width: 100%; background-color: #A0A0A0; padding: 6px; }
div#menu a { color: #404040; text-decoration: none; padding-left: 15px;}
div#contents { margin: 30px; }
</style>
</head>
<body>
<h1>{{ $apptitle }}</h1>
<div id="menu">
<a href="index.php?page=home">Home</a>
<a href="index.php?page=about">About</a>
<a href="index.php?page=contact">Contact</a>
</div>
<h2>[: block page :]Index[: endblock :]</h2>
<div id="contents">
[: block contents :][: endblock :]
</div>
</body>
</html>