2011年8月23日 星期二

php 使用template

在網路上找到的,基本上都是給那些懂php寫得……對我這個初學者而也很不友善也不是很懂…… 於是自己摸索出最基本了……(我只是想找最最最基本的原理而已啊……(淚)) 以下是我的template(/template/template.html)
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>This is a simple template</title>
		<style>body{color: rgba(11,12,13,0.8)}</style>
	</head>
	<body>
		{main}
	</body>	
</html>
然後是我的load template php file(/loadTemp.php)
<?php
list($tempTop, $tempBottom) =
	split("{main}", file_get_contents('template/template.html', true));
?>
然後這是引用模板的其中一個網頁(/simplePage.php)
<?php include "loadTemp.php" ; ?>
<?php echo $tempTop;?>
This is my main text
<?php echo $tempBottom;?>
這算是最基本的用法啦…… 如果還需要再增加……譬如說論壇bbcode語法就要再另外追加code了…… 另外,如果要用js而folder如下:
 |-----index.php  |-----loadTemp.php  |-----simplePage.php  |-----template  |      |-----template.html  |-----js  |      |-----script.js
請別忘記template.html中是寫
<script src="js/script.js"></script">
而不是../js/script.js

沒有留言:

張貼留言