473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Templates

hello,

is this the right place to post questions or what?

anyway i'm trying to make a simple template system using php,
here is:
a page using the template: http://www.yehiaeg.com/focusonvbs/test.php
the header: http://www.yehiaeg.com/focusonvbs/temp1.inc
the footer: http://www.yehiaeg.com/focusonvbs/temp2.inc

but don't know why the page using the template is messed up,

it should like this http://www.yehiaeg.com/focusonvbs/desc.htm ,
any ideas?

Yehia
Jul 17 '05 #1
15 1689
"Yehia" <ye***@yehiaeg.com> wrote in message
news:e5**************************@posting.google.c om...
anyway i'm trying to make a simple template system using php,
here is:
a page using the template: http://www.yehiaeg.com/focusonvbs/test.php
the header: http://www.yehiaeg.com/focusonvbs/temp1.inc
the footer: http://www.yehiaeg.com/focusonvbs/temp2.inc

but don't know why the page using the template is messed up,

it should like this http://www.yehiaeg.com/focusonvbs/desc.htm ,
any ideas?


well without seeing your code, it is hard to tell, exept that you have got
something wrong :) . Have you considered using some existing template system
for php?

rush
--
http://www.templatetamer.com/
Jul 17 '05 #2
Nel
"rush" <pi**@rush.avalon.hr> wrote in message
news:cd**********@ls219.htnet.hr...
"Yehia" <ye***@yehiaeg.com> wrote in message
news:e5**************************@posting.google.c om...
anyway i'm trying to make a simple template system using php,
here is:
a page using the template: http://www.yehiaeg.com/focusonvbs/test.php
the header: http://www.yehiaeg.com/focusonvbs/temp1.inc
the footer: http://www.yehiaeg.com/focusonvbs/temp2.inc

but don't know why the page using the template is messed up,

it should like this http://www.yehiaeg.com/focusonvbs/desc.htm ,
any ideas?
well without seeing your code, it is hard to tell, exept that you have got
something wrong :) . Have you considered using some existing template

system for php?

rush
--
http://www.templatetamer.com/

If it's any help I would recommend a different method, not necessarily
better for everyone, but for me.

Create a HTML template in your authoring packaging, preferably using CSS.

Then in place your own tags anywhere on the page, where you would like to
swap the tag for some variable.

e.g. {{pagetitle}} or {{pagetext}}

Then save that as a file called template.htm

Then read your template.htm file in as array, get your pagetitle and
pagetext (+ other variables) from your database (I assume) and use
preg_replace to change over your tags to the appropriate string. (see
below). Then you just have to output your page!

Nel

$template = "";
$temp = file($setuptemplate);
foreach($temp as $line) { $template .= $line; }

// update template with menus and content
$pat = array("/{{pagetext}}/s",
"/{{pagetitle}}/s",
"/{{topmenuh}}/s",
"/{{topmenuv}}/s",
"/{{submenuh}}/s",
"/{{submenuv}}/s"
);
$rep = array("$pagetext",
"$pagetitle",
"$topmenuh",
$topmenuv,
"$submenuh",
$submenuv
);
// replace all occurrences of search patterns with according replacements

$template = preg_replace($pat, $rep, $template);

echo $template;
Jul 17 '05 #3
> anyway i'm trying to make a simple template system using php,
here is:
a page using the template: http://www.yehiaeg.com/focusonvbs/test.php
the header: http://www.yehiaeg.com/focusonvbs/temp1.inc
the footer: http://www.yehiaeg.com/focusonvbs/temp2.inc


Your problem is with the HTML, not the PHP. Delete the </table> tag at the
end of temp1.inc, and that should fix the biggest layout errors.

Chris Finke
Jul 17 '05 #4
Nel
Forgot to say, main advantage of preg_replacing your own tags is that you
don't have to split your template in to a header and footer, so you can
change the template simply by loading any new html page containing your
tags.

Nel.
Jul 17 '05 #5
Yehia wrote:
hello,

is this the right place to post questions or what?

anyway i'm trying to make a simple template system using php,
here is:
a page using the template: http://www.yehiaeg.com/focusonvbs/test.php
the header: http://www.yehiaeg.com/focusonvbs/temp1.inc
the footer: http://www.yehiaeg.com/focusonvbs/temp2.inc

but don't know why the page using the template is messed up,

it should like this http://www.yehiaeg.com/focusonvbs/desc.htm ,
any ideas?

Yehia


Have you thought of using the Smarty template system?
http://smarty.php.net/

It's really easy to get going with it and does what Nel has recommended.
Jul 17 '05 #6
actually the html work well:
http://www.yehiaeg.com/focusonvbs/version.htm,

and here is the contents of test.php :
_____________________________________________
<html>
<head>
<title>YehiaEg &gt; Products &gt; Focus On VBS &gt; Download</title>
<?php
include 'temp1.inc';
?>
<p class="NormalFont"><br>
Latest version: 1.5<br>
Size: 509 KB <br>
License: Demo<br>
Requirements: None<br>
Download Link: <a
href="http://www.yehiaeg.com/focusonvbs.exe">Click Here</a>
<br><br>
<strong>Note:</strong> "Save /As", "Cut", "Copy", are disabled
in this demo version.<br><br>
Available also on <a
href="http://www.download.com/Focus-on-VBS/3000-2352-10223282.html?tag=lst-0-1"><img
src="cnet.gif" width="127" height="27" border="0"></a>
</p>
<?php
include 'temp2.inc';
?>
__________________________________________________ ___
All i did was just opening the original htm file and copy every before
the main text in temp1.inc and everything after in temp2.inc ,

Don't know what i'm doing wrong, PLZ help guys.
"Christopher Finke" <ch***@efinke.com> wrote in message news:<2l************@uni-berlin.de>...
anyway i'm trying to make a simple template system using php,
here is:
a page using the template: http://www.yehiaeg.com/focusonvbs/test.php
the header: http://www.yehiaeg.com/focusonvbs/temp1.inc
the footer: http://www.yehiaeg.com/focusonvbs/temp2.inc


Your problem is with the HTML, not the PHP. Delete the </table> tag at the
end of temp1.inc, and that should fix the biggest layout errors.

Chris Finke

Jul 17 '05 #7
On Fri, 16 Jul 2004 02:14:31 -0700, Yehia wrote:
All i did was just opening the original htm file and copy every before
the main text in temp1.inc and everything after in temp2.inc ,

Don't know what i'm doing wrong, PLZ help guys.


Evidently, you didn't do quite what you say you did.

Take the pages as produced in your browser. Save each -- the working HTML
file and the PHP file that doesn't quite work -- and compare the two
documents. (here is where a Unix-like OS comes in handy: use the diff
command. Or are you using Windows?)

diff desc.htm test.php.html | less

Compare the two files *carefully*!! Look at the differences -- there are
MANY. There should be NONE! You want the final output from your PHP page
to look EXACTLY like the original HTML page, but it doesn't.

So, then, my question to you is: How can your PHP page end up looking
exactly like your HTML draft page?
later...

--
Jeffrey Silverman
je*****@jhu.edu

Jul 17 '05 #8
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in message news:<40*********************@ptn-nntp-reader03.plus.net>...
<snip>
If it's any help I would recommend a different method, not necessarily
better for everyone, but for me.

Create a HTML template in your authoring packaging, preferably using CSS.

Then in place your own tags anywhere on the page, where you would like to
swap the tag for some variable.

e.g. {{pagetitle}} or {{pagetext}}

Then save that as a file called template.htm

Then read your template.htm file in as array, get your pagetitle and
pagetext (+ other variables) from your database (I assume) and use
preg_replace to change over your tags to the appropriate string. (see
below). Then you just have to output your page!

Nel

$template = "";
$temp = file($setuptemplate);
foreach($temp as $line) { $template .= $line; }

// update template with menus and content
$pat = array("/{{pagetext}}/s",
"/{{pagetitle}}/s",
"/{{topmenuh}}/s",
"/{{topmenuv}}/s",
"/{{submenuh}}/s",
"/{{submenuv}}/s"
);
$rep = array("$pagetext",
"$pagetitle",
"$topmenuh",
$topmenuv,
"$submenuh",
$submenuv
);
// replace all occurrences of search patterns with according replacements

$template = preg_replace($pat, $rep, $template);

echo $template;


Templates are one of the most controversial topic, at least in
this group. For example,
<http://groups.google.com/groups?threadm=c17ndg%24l3t%241%40newsreader.mailg ate.org>

* "Using a template system is a little like going back to using PHP
1--you get a far less powerful, less flexible system to work with." --
phpSt.Chung Leong
* "What about PHP ?-)" -- phpSt.Bruno Desthuilliers

Also see:
1. http://www.phpbuilder.com/annotate/m...hp3?id=1013434
2. http://www.phpbuilder.com/annotate/m...hp3?id=1013711
3. http://www.phpbuilder.com/annotate/m...hp3?id=1013461
4. http://www.phppatterns.com/index.php...cleview/4/1/1/
5. http://www.massassi.com/php/articles/template_engines/
6. http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #9
don't want to use any third party code, i'm happy with the php include function,

anyway, still want to know why my code doesn't work!
neur0maniak <us****@neur0maniak.co.uk> wrote in message news:<40***********************@ptn-nntp-reader02.plus.net>...
Yehia wrote:
hello,

is this the right place to post questions or what?

anyway i'm trying to make a simple template system using php,
here is:
a page using the template: http://www.yehiaeg.com/focusonvbs/test.php
the header: http://www.yehiaeg.com/focusonvbs/temp1.inc
the footer: http://www.yehiaeg.com/focusonvbs/temp2.inc

but don't know why the page using the template is messed up,

it should like this http://www.yehiaeg.com/focusonvbs/desc.htm ,
any ideas?

Yehia


Have you thought of using the Smarty template system?
http://smarty.php.net/

It's really easy to get going with it and does what Nel has recommended.

Jul 17 '05 #10
Yehia wrote:
don't want to use any third party code, i'm happy with the php include function,

anyway, still want to know why my code doesn't work!


Okay, how about doing the reverse of what you're trying to do?

The way I do simple "include style" templates is this:

You've got the HTML template you'd like to use, call that 'index.php'

Insert this code at the top:
$strPage=trim($_GET["p"]);
if (strlen($strPage)==0) {$strPage="main";} //This is your default page
if (!file_exists("pages/{$strPage}.php")) {$strPage="404";}

Create a folder called 'pages' in the folder of 'index.php'
Place your pages in that folder, all with a '.php' extension.
Make sure you make one called "404.php" for when a user tries a URL
where a page is missing.
In 'index.php' replace the content area of your template with:
<?php include ("pages/{$strPage}.php"); ?>

From then on, you can access pages by using 'index.php?p=pagename'
This saves you from using two pages for your template.

Things to keep in mind:
When submitting a FORM using METHOD="GET", make sure you have a INPUT
tag of TYPE="HIDDEN", NAME="p", and VALUE="pagename" (If you don't then
you'll not submit to the page you want to)
You can't set headers/cookies in your pages, as output takes place
before the page is included, though there are many ways of working
around it..
Jul 17 '05 #11
In article <40**********************@ptn-nntp-reader01.plus.net>, neur0maniak wrote:
Yehia wrote: Insert this code at the top:
$strPage=trim($_GET["p"]);
if (strlen($strPage)==0) {$strPage="main";} //This is your default page
if (!file_exists("pages/{$strPage}.php")) {$strPage="404";}


?p=../index
--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
Jul 17 '05 #12
Tim Van Wassenhove wrote:
In article <40**********************@ptn-nntp-reader01.plus.net>, neur0maniak wrote:
Yehia wrote:


Insert this code at the top:
$strPage=trim($_GET["p"]);
if (strlen($strPage)==0) {$strPage="main";} //This is your default page
if (!file_exists("pages/{$strPage}.php")) {$strPage="404";}

?p=../index

$strPage=trim($_GET["p"]);
if (strlen($strPage)==0 || substr($strPage, "..")!==false)
{$strPage="main";} //This is your default page
if (!file_exists("pages/{$strPage}.php")) {$strPage="404";}

Jul 17 '05 #13
neur0maniak wrote:
Tim Van Wassenhove wrote:
In article <40**********************@ptn-nntp-reader01.plus.net>,
neur0maniak wrote:
Yehia wrote:

Insert this code at the top:
$strPage=trim($_GET["p"]);
if (strlen($strPage)==0) {$strPage="main";} //This is your default
page
if (!file_exists("pages/{$strPage}.php")) {$strPage="404";}


?p=../index

$strPage=trim($_GET["p"]);
if (strlen($strPage)==0 || substr($strPage, "..")!==false)
{$strPage="main";} //This is your default page
if (!file_exists("pages/{$strPage}.php")) {$strPage="404";}

urgh... replace substr with strpos
Jul 17 '05 #14
ok, i did copy them EXACTLY and it kinda worked but still have some
questions:
1.when using javascript in a php file should i write like this
<script language="javascript> <!-- some function --> </script>
or like this <script language="javascript"> some function </script>

2. somethings may vary from one page to another besides its content
like the page title, what is the simplest way to do this?
i read about sending arguments to the php file and then assign to the
page title, but this not really neat, what if i want to make it a long
title:
test.php?pagetitle=This a really long title, really long
one............
Anyother wahy to do this?

my questions might look stupid but i'm just really a beginner in php,
Thanks

neur0maniak <us****@neur0maniak.co.uk> wrote in message news:<40***********************@ptn-nntp-reader02.plus.net>...
Yehia wrote:
hello,

is this the right place to post questions or what?

anyway i'm trying to make a simple template system using php,
here is:
a page using the template: http://www.yehiaeg.com/focusonvbs/test.php
the header: http://www.yehiaeg.com/focusonvbs/temp1.inc
the footer: http://www.yehiaeg.com/focusonvbs/temp2.inc

but don't know why the page using the template is messed up,

it should like this http://www.yehiaeg.com/focusonvbs/desc.htm ,
any ideas?

Yehia


Have you thought of using the Smarty template system?
http://smarty.php.net/

It's really easy to get going with it and does what Nel has recommended.

Jul 17 '05 #15
Yehia wrote:
ok, i did copy them EXACTLY and it kinda worked but still have some
questions:
1.when using javascript in a php file should i write like this
<script language="javascript> <!-- some function --> </script>
or like this <script language="javascript"> some function </script>

2. somethings may vary from one page to another besides its content
like the page title, what is the simplest way to do this?
i read about sending arguments to the php file and then assign to the
page title, but this not really neat, what if i want to make it a long
title:
test.php?pagetitle=This a really long title, really long
one............
Anyother wahy to do this?

my questions might look stupid but i'm just really a beginner in php,
Thanks


1. Either will work, the commented version is better for browsers though.

2. Create another folder (like pages, but call this one 'headers' or
such. Then add this code underneath where $strPage is assigned:

if (file_exists("headers/{$strPage}.php"))
{include("headers/{$strPage}.php");}

The .php in the headers folder would need to be pure php (no out put, no
empty spaces before/after the PHP tags).
Inside the PHP, you could have
<?php $strTitle = "Different Title"; ?>

Then, in your template page where you set your title, you could have
something like this:
<TITLE><?php if (strlen(trim(@$strTitle))>0) {print
$strTitle;}else{print "Normal Title"; ?></TITLE>

The file in the headers folder will need the same filename as the file
in the pages folder. You don't need to put a file in the headers folder,
for each one you have in your pages folder, just ones that change something.

This way you can put anything that changes headers or adds cookies on a
page using the file in the headers folder.
Jul 17 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vince C. | last post by:
Hi all, I've created XML documents that are described with a schema. I'm using those documents to create web pages. All my web pages contain a fixed header and a variable document part. The...
5
by: Tom Alsberg | last post by:
Hi there... I'm recently trying to get a bit acquainted with XML Schemas and XSL. Now, I have a few questions about XSL stylesheets and templates: * Is there a way to "enter" a child element...
22
by: E. Robert Tisdale | last post by:
According to the C++ FAQ Lite: http://www.parashift.com/ What is "genericity"? Yet another way to say, "class templates." Not to be confused with "generality" (which just means avoiding...
12
by: Fabio De Francesco | last post by:
Hello. I can't understand why I can't compile the following simple code, where I think I have applied all the needed rules for templates that are declared and defined in different files (*.h and...
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
2
by: jimbo_vr5 | last post by:
Hey I think i've figured out the idea behind apply-templates. But going through the tutorial on <http://www.w3schools.com/xsl/xsl_apply_templates.asp> theres simply just something that i dont...
25
by: Ted | last post by:
I'm putting the posts that follow here (hopefully they will follow here!) because they were rejected in comp.lang.c++.moderated. It behooves anyone reading them to first read the the thread of the...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
104
by: JohnQ | last post by:
Well apparently not since one can step thru template code with a debugger. But if I was willing to make the concession on debugging, templates would be strictly a precompiler thing? I have a...
7
by: Chris | last post by:
Hi All, This is a weird one but I am hoping someone can help or has some pointers, a recipe how to do the following: I have to move some code from c++ to objective-c and to do this I must...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.