473,795 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using the same template for each page

I'm making a website where each page has the same design, obviously its
a bad idea to put the same code/html in each page so what is the best
way to do this?

What I'm doing at the moment is putting a file called 'index.php' and a
file called 'content.php' in each directory. 'index.php' would set a
variable called $content with the full path for 'content.php' then it
would have an include() statement which called a script outside
public_html called 'template.php'. 'template.php' would be the basic
template for every page and where the content is it would have the line
'include($conte nt);'. Here's what my scripts basically look like:

--
/www/mysite/public_html/subpage/index.php:

<?php
$content = "/www/mysite/public_html/subpage/content.php":
include("/www/mysite/private_html/template.php");
?>
--
/www/mysite/public_html/subpage/content.php:

<h2>Content goes here</h2>
--
/www/mysite/private_html/template.php

<title>mysite </title>
<h1>welcome to my site</h1>
<?php include($conten t); ?>
--

This all works as it should, but I'm just wondering is there a better
way to go about this? I've found that it creates a lot of work when I
move or rename directories and also when I move the scripts between
servers as the full path will change and every index.php will need to
be updated. Sites like eBay and Amazon have the same design for each
page, how are they likely to be doing it?

Aug 29 '05 #1
3 1713
"J Smith" <ha**********@g mail.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
I'm making a website where each page has the same design, obviously its
a bad idea to put the same code/html in each page so what is the best
way to do this?


There are several ways to accomplish what you would like, and the best one
is more matter of personal preferences tha and absulute category.

Aside from approach, you could use some of existing template systems, or you
could base your work on XML+XSLT approach.

I am obviously biased, but should you choose to try out TemplateTamer,
please do not hesitate to mail me if you have any questions.

rush
--
http://www.templatetamer.com/
http://www.folderscavenger.com/
Aug 29 '05 #2
max
On 29 Aug 2005 06:01:01 -0700, "J Smith" <ha**********@g mail.com> wrote:
I'm making a website where each page has the same design, obviously its
a bad idea to put the same code/html in each page so what is the best
way to do this?

What I'm doing at the moment is putting a file called 'index.php' and a
file called 'content.php' in each directory. 'index.php' would set a
variable called $content with the full path for 'content.php' then it
would have an include() statement which called a script outside
public_html called 'template.php'. 'template.php' would be the basic
template for every page and where the content is it would have the line
'include($cont ent);'. Here's what my scripts basically look like:

--
/www/mysite/public_html/subpage/index.php:

<?php
$content = "/www/mysite/public_html/subpage/content.php":
include("/www/mysite/private_html/template.php");
?>
--
/www/mysite/public_html/subpage/content.php:

<h2>Content goes here</h2>
--
/www/mysite/private_html/template.php

<title>mysit e</title>
<h1>welcome to my site</h1>
<?php include($conten t); ?>

If you have access to an MySQL database (and most web hosts offer this for
notta lotta money these days) you can have an index file carrying a list of
content records in a database.
The principle behind it is that you identify to your content.php file which
record in the database you want to display.
Unless the directory structure is essential to your design, you should be
able to do without it.

In index.php, you might have -

$TableName="tit les_of_content" ;
$Query="SELECT title_of_conten t FROM $TableName";
$Result=mysql_d b_query ($DBName, $Query, $Link);
while ($Row=mysql_fet ch_array($Resul t))
{
print("<a href=\"content. php?id=$Row[title_of_conten t]\"></a>");
}
This prints out a clickable URL for each "title_of_conte nt" record in the
database; run your cursor over the list and you'll see the id= change.

In content.php, you have -

$TableName="tit les_of_content" ;
$Query="SELECT * FROM $TableName WHERE title_of_conten t='$title_of_co ntent'
";
$Result=mysql_d b_query ($DBName, $Query, $Link);
while ($Row=mysql_fet ch_array($Resul t))
{
do things
}

Put
php "passing variables" tutorial
into google and try any one of the numerous results you feel comfortable
reading.

HTH.
Aug 29 '05 #3
On Mon, 29 Aug 2005 06:01:01 -0700, J Smith wrote:
I'm making a website where each page has the same design, obviously its
a bad idea to put the same code/html in each page so what is the best
way to do this?

<snip>

I do the following:
I have Menu.php and Trailer.php in the "components " directory.
Each page then does:
include (components/Menu.php)
content
include (components/Trailer.php)

Menu.php includes the standard header and a menu bar but also includes a
sidebar which (someday) will contain content from our calendar. From here
you can also add whatever code that needs to be executed for every page.
I use this for login and session handling, personalizing the header for
the logged in user, etc.

Since we have the sidebar, the Menu.php ends with a table. The first
column in the table is the sidebar and the <TD> for the second column (the
content) is written.

The content then displays from the page issuing the include(Menu).

The Trailer.php script then closes the </TD> and writes out the footer for
the page.

This keeps the standard stuff in singular places and the content whereever
it needs to be.

Chris
Aug 29 '05 #4

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

Similar topics

2
3409
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only happening when I put my XML files and the .xsl files on my ISP's system for my home page. If I try to open the XML files in Netscape 7.0 on my own machine (ie, not on the ISP's system), the pages convert file and the result is displayed in HTML.
3
2012
by: Brynjar Glesnes | last post by:
Hi, I've browsed the Fop FAQ, usenet and the internet hoping to find a solution to my problem, but in vain. I am using Xerces 2.6.2, Xalan-J 2.6.0 and Fop 0.20-5 to create PDF-documents. In the rendered PDF there is an unwanted whitespace after each xsl:value-of. An example: What I want to render to "Doe, John" renders to "Doe ,
3
1589
by: nevets2001uk | last post by:
Hi. I've just started my second ASP.NET (VB) app and I'm using codebehind this time. I'm not using visual studio but am instead coding it all in notepad (HTML, ASP.NET and CSS) I'm trying to understand how to best use codebehind to do what I want to achieve. Basically, so far I have a codebehind file for one page which works as I wanted but I want other pages to share that codebehind file. That's no problem except I want each one to...
3
2383
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central panel. The central panel is intended to display the main content of the cv: when an anchor is selected from the header then the detail is supposed to appear. The javascript is supposed to select the appropriate section 'onclick' and output it....
10
1920
by: William Krick | last post by:
I am writing an XSL transform that converts XML data about vehicles into XML data that will fill printed forms. The default form can handle up to 5 vehicles which I handle using subscripts... <xsl:for-each select="VEHICLE"> <!-- spit out some stuff about this vehicle --> </xsl:for-each> <xsl:for-each select="VEHICLE">
4
2196
by: Per Bolmstedt | last post by:
(This question has been asked previously in this group, but I don't think it was ever really properly answered.) I want to use reflection - preferably - to find all Web Forms in my web site that inherit my base page class (which in turn inherits System.Web.UI.Page). Behold the following code: For Each asm As System.Reflection.Assembly In System.AppDomain.CurrentDomain.GetAssemblies() For Each mdl As System.Reflection.Module In...
2
2840
by: rn5a | last post by:
Please have a look at the image at the URL given below: http://rn5a.brinkster.net/Template.gif I would like to use that image as a template for all the ASP pages in a website. Note that though it looks like a frames page, it's actually not a frames page. Using different images has made it look like a frames page. The "Your Site Name" header, the 5 links "Home", "About", "Forums",
8
8949
by: =?Utf-8?B?Q2hyaXMgSGFsY3Jvdw==?= | last post by:
Hi there I've successfully added some .NET validation controls to a page (using <asp:RequiredFieldValidator ...), however when I try to set the 'display' property to 'dynamic', my page then throws up the following error in the browser: CS1061: 'System.Web.UI.WebControls.TextBox' does not contain a definition for 'Web' and no extension method 'Web' accepting a first argument of type 'System.Web.UI.WebControls.TextBox' could be found...
3
3702
by: saritha2008 | last post by:
Hi, As part of migrating bugs from JIRA to BugZilla, below is the requirement: If there are multiple “version” tags in my input.xml file For open bugs (Resolved,Reopened,Inprogress,NeedInfo) > create multiple bugs, one for each “version". “Fix version” will be empty. For closed bugs > create multiple bugs, one for each “Fixed in” version. Use earliest “version" for all bugs. I tried using the apply-template in the XSLT for the above...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10436
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.