Forum Moderators: coopster
I have a .php file that I want to use as a template.
The files that I will use with this template file will have very simple scripts such as:
<p>a paragraph of text</p>
<p>a paragraph of text</p>
<p>a paragraph of text</p>
<p>a paragraph of text</p>
I want to know how I do it.
IMPORTANT:
I am not looking for something like:
<?php include "header.php");?>
text
<?php include "footer.php");?>
In between is not gonna work for me.
I need a template file which I can use as a reference which will already have enough of php include's in it.
text will be just for one of the table cells.
thanks.
Thanks for the nice welcome!
What I meant was:
In my template file I also have other php files inserted by <?php include
I also have a couple of tables in the very same template file. (meaning table as in <table>)
And the "text" I mentioned will be put in a cell of one of these tables. (<td>)
The template file is actually is an html file with different php files "include"d in some certain cells.
Anyways, below is the actual template that I want to use.
All I want to add to it with the other file is {tpl_title} and {tpl_head_text}. you can see below where I want them.
thanks.
----------
<html>
<head>
<title>FiscalStudy.com - {tpl_title}</title>
<link rel="stylesheet" type="text/css" href="http://www.example.com/css1.css" />
<link rel="stylesheet" type="text/css" href="http://www.example.com/css2.css" />
</head>
<body>
<?php include("http://www.example.com/header.php");?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top" width="15%"><font size="1"><br></font>
<?php include("http://www.example.com/menu.php");?>
</td>
<td width="1%" valign="top" class="vertical"> </td>
<td valign="top" width="2%"> </td>
<td valign="top" width="82%"><div align="center">
<p> </p>
<table width="62%" border="0" align="center" cellpadding="0" cellspacing="0" style="border: 2px solid #000000">
<tr>
<td bgcolor="#000000"><div align="right"><font color="#FFFFFF" size="3">News
Flash of the Week</font></div></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> <div align="center"><strong>{tpl_title}</strong></div></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><div align="justify">{tpl_head_text}</div></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><hr color="#000000" size="1"></td>
</tr>
<tr>
<td><div align="center"><a href="http://www.example.com/flash/preflash.php"><font size="2"><u>previous
weeks' flashes!</u></font></a><font size="1"></font></div></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<p> </p>
</div>
</td>
</tr>
</table>
<?php include("http://www.example.com/footer.php");?>
</body>
</html>
[edited by: jatar_k at 6:45 pm (utc) on Mar. 19, 2004]
[edit reason] generalized urls [/edit]
<?php
$tpl_title = 'My Title';
$tpl_head_text = 'Heading Text';
?>
<html>
<head>
...
<title>FiscalStudy.com - <?php print $tpl_title;?></title>
...
<td><div align="center"><strong><?php print $tpl_title;?></strong></div></td>
...
<td><div align="justify"><?php print $tpl_head_text;?></div></td>
...
<?php
$tpl = implode( '' , file( 'template.php' ) );
$search = array( '{tpl_head_text}' , '{tpl_title}' );
$replace = array( 'h1 title text' , 'this is the page title' );
$str = str_replace( $search, $replace , $tpl );
echo $str;
?>
But with that, I had trouble with the php inclusions in the template file. They just did not work.
Please help.
thanks.
if (file_exists($templatefile)) {
$newFile=fopen($templatefile,"r");
//read out the content
$fileContent=fread($newFile,filesize($templatefile));
//close the file
fclose($newfile);
$search = array( '{tpl_head_text}' , '{tpl_title}' );
$replace = array( 'h1 title text' , 'this is the page title' );
$str = str_replace( $search, $replace , $fileContent );
}
Try this one =)
But, pls note, this is a very simple example, and should not declared as a template System *G*
I really like what you are suggesting.
It would be so easy to implement it as follows:
<?php
$title = "whatever title!";
$text = "whatever text";
?>
<?php include ("flashtemplate.php");?>
But my problems is, for the $text, I have to insert a text with html codes which is as long as 5 paragraphs. Something like:
<p>a paragraph of text</p>
<p>a paragrapg of text</p>
<p>a paragrapg of text</p>
<p>a paragrapg of text</p>
<p>a paragrapg of text</p>
How can I do it without making a text inclusion from a third file?
Alternately, you could set up all your paragraphs and just include the template. That's usually my preference.
pg1.php
<?
$para1 = <<<PARA1
This is <span>paragraphs one</span> with html in it and everything
PARA1
$para23 = <<<PARA23
This is <span>paragraphs two and three</span> with html in it and everything
PARA23
include("T_default.php");
?>
file: T_default.php
<?
include("header.inc.php");
echo "<p>$para1</p>";
echo "<p>$para23</p>";
include("footer.inc.php");
?>
include
HTMl file
<table width="760" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#0066CC">
<tr>
<th height="25" colspan="2" bgcolor="#99CCFF" scope="col"><div align="left">{#$type#}</div></th>
</tr>
<tr>
<td width="150" rowspan="2" valign="top" bgcolor="#DAE9F5">{#include file=$search#} <p> </p></td>
<td valign="top" bgcolor="#DAE9F5"><div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<th scope="col"><span class="style3">{#$title#}</span><br>
{#$date#} </th>
</tr>
</table>
</div></td>
</tr>
<tr>
<td valign="top" bgcolor="#DAE9F5">{#$content#}</td>
</tr>
</table>
php file
//开始smarty配置设置-------------------------------------------------------
include "class/Smarty.class.php";
define('__SITE_ROOT', 'd:\phpsite\adodbnews'); // 最後沒有斜線
$tpl = new Smarty();
$tpl->template_dir = __SITE_ROOT . "/page/";
$tpl->compile_dir = __SITE_ROOT . "/templates_c/";
$tpl->config_dir = __SITE_ROOT . "/configs/";
$tpl->cache_dir = __SITE_ROOT . "/cache/";
$tpl->left_delimiter = '{#';
$tpl->right_delimiter = '#}';
//结束smarty配置设置-------------------------------------------------------
$tpl->assign("title", $array_news["title"]);
$tpl->assign("content", $array_news["content"]);
$tpl->assign("date", $array_news["date"]);
$tpl->assign("typeid", $array_news["typeid"]);
$tpl->display('office/show_info.htm');