แสดงบทความที่มีป้ายกำกับ php template แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ php template แสดงบทความทั้งหมด

วันอาทิตย์ที่ 19 ธันวาคม พ.ศ. 2553

layout-views or master-contents page

master-page.php

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<link type="text/css" rel="stylesheet" href="style.css"/>
<title>{$title}</title>
{$head}
</head>

<body>
<h1>Welcome to my site</h1>
<table width="800" border="2"><tr><td bgcolor="#FFCC00">
{$content1}
</td><td bgcolor="#FFFFCC">
{$content2}
</td></tr>
</table>
<hr/>
easy master page by num |
<a href="normal-page.php">page1</a> |
<a href="normal-page2.php">page2</a>
</body>
</html>


normal-page.php

<?php require 'util.php'; $MasterPage = 'master-page.php';?>
<?php if (0):?><meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<link type="text/css" rel="stylesheet" href="style.css"/><?php endif;?>

<?php sb('title'); echo 'test-title'; eb();?>

<?php sb('head');?>
<script type="text/javascript">
window.onload = function(){
document.getElementById('test').innerHTML = 'javascript text';
}
</script>
<?php eb();?>

<?php sb('content1');?>
<b>hello world</b>
<div id="test"></div>
<?php eb();?>

<?php sb('content2');?>
lksldfjksjdklfjk lsjdlkfj s dfjsldkjfks jdklfjkljsdl fklsjdklfjlksd
<?php eb();?>


<?php render();?>


normal-page2.php

<?php require 'util.php'; $MasterPage = 'master-page.php';?>
<?php if (0):?><meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<link type="text/css" rel="stylesheet" href="style.css"/><?php endif;?>

<?php sb('title'); echo 'สวัสดีครับ'; eb();?>

<?php sb('head');?>
<?php eb();?>


<?php sb('content1');?>
page2
<?php eb();?>

<?php sb('content2');?>
this is page 2.
<?php eb();?>



<?php render();?>


util.php

<?php

$_vars = array();
function sb($name){
static $sName;
if (empty($name)) return $sName;
$sName = $name;
ob_start();
}
function eb(){
global $_vars;
$name = sb(0);
$_vars[$name] = ob_get_clean();
}
function render(){
global $_vars;
ob_start();
require ($GLOBALS['MasterPage']);
$page = ob_get_clean();
foreach($_vars as $name=>$var)
$page = str_replace('{$'.$name.'}',$var,$page);
echo $page;
}

?>



/* CSS Document */

*{margin:0;padding:0;}
body {background-color:#ccc;}

วันจันทร์ที่ 25 ตุลาคม พ.ศ. 2553

easy php template

index.php

<?php ob_start(); #require 'connect.php'; ?>
<script type="text/javascript">
window.onload = function(){
document.getElementById('test').innerHTML = 'content by js.';
}
</script>
<?php $tp_script = ob_get_clean(); ob_start(); ?>

<?php $tp_title = 'template designer';?>
<div>hello template world</div>
<div id="test"></div>

<?php $tp_content = ob_get_clean(); include 'tpl.php'; ?>


tpl.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=x-windows-874">
<title><?php echo empty($tp_title)?'':$tp_title;?></title>
<?php echo empty($tp_script)?'':$tp_script;?>
</head>
<body>
<!-- template editable in dreamweaver -->
<?php echo $tp_content;?>
</body>
</html>