Forum Moderators: coopster

Message Too Old, No Replies

OO external template

         

music_man

6:20 am on Oct 30, 2006 (gmt 0)

10+ Year Member



Hi

I am trying to figure out how to make an external .tpl file with all the HTML and call it from the Object.

So:

index.php


<?php
include "classes/website.class.php";
$site = new Page;
$site->getPage();
$site->Title = "Welcome";
$Content = 'Welcome to my website'
';
$site->SetContent( $Content );
$site->Display( );
?>

website.class.php


<?php

class Page
{
var $Title;
var $Content;
var $CurrentPage;
function showMeta() {

$pre_content = trim(strip_tags($this->Content));
$string_length = 500;
$count = strlen($pre_content);
if ($count >= 100)
{
$content_almost = trim(substr($pre_content,0,$string_length));
$content_there = $content_almost . "...";
echo $content_there;
}

}
function currentCSS() {

$pageshorter = substr($this->CurrentPage, 0, 4);

echo 'body.' . $pageshorter . ' #navigation li.' . $pageshorter .
'a { background-color:#9c6; color:white; }';
}

function currentBody() {
$pageshorter = substr($this->CurrentPage, 0, 4);
echo $pageshorter;
}
function getPage()
{
/* thanks <snip> */
$currentFile = $_SERVER["SCRIPT_NAME"];
$parts = Explode('/', $currentFile);
$currentFile = $parts[count($parts) - 1];
$this->CurrentPage = $currentFile;
}
function ShowNav()
{
$nav = array('Home' => 'index.php', 'About me' => 'about.php', 'Private Lessons' => 'private.php', 'Group classes' => 'group.php', 'Workshops' => 'workshops.php');
foreach ($nav as $pagename => $pagelink)
{
$pageshorter = substr($pagelink, 0, 4);
echo '<li class="' . $pageshorter . '"><a href="' . $pagelink . '">' . $pagename . '</a></li>';
}
}
function SetContent( $Data )
{
$this->Content = $Data;
}
}
?>

website.tpl


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta content="'. $content_there . '" />
<title>{$this->Title}</title>
<link rel="stylesheet" href="style.css" />
<style type="text/css">
{$this->currentCSS()}
</style></head><body class="{$this->currentBody()">
<div id="container">
<div id="content">
<div id="header"><span id="imageposition"></span> <img src="img/header.gif" /> </div>
<br /><br />
<div id="navigation">
<ul>{$this->ShowNav()}</ul>
</div>
<div id="siteinfo">';
{$this->Content}
</div>
<div id="footer">Footer</div>
</div>
<div id="curve">&nbsp;</div>
</div>
</body>
</html>

What do I have to include in the object and in index.php for it to use the .tpl file please?

[edited by: dreamcatcher at 12:01 pm (utc) on Oct. 30, 2006]
[edit reason] No URLs, thanks. [/edit]

henry0

12:20 pm on Oct 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi
A few days ago I made some demo/tutor

HERE
[webmasterworld.com]
Look how it was built.
(it's somewhere down the thread)