Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

identical nesting of tables across many pages - how can i simplify? 2

Status
Not open for further replies.

xioni

Technical User
Nov 11, 2007
8
US
hi,

i know next to nothing about how to do this.

i am working on a set of pages in xhtml using a css style sheet. each of these pages displays text surrounded by an identical nesting of tables and such.

instead of repeating this identical nesting of tables for each page, is there a way i can define the structure as some sort of template, perhaps in the css file, and then call on it within each page?

if this is possible, i want to make sure that it is supported by most browsers, especially on phones and other portable devices.


any advice, pointers, and details would be greatly appreciated!

thank
 
You can do this with any garden variety server-side language.
And since its server side, its perfectly compliant with everything, as everything that will be delivered is standard html.

Now you need to know what server side language your webhost supports, and then ask in the forum for it how to do it.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
okay, that's good to know.

so, the webhost is server at a university and i believe it supports various server side languages. i won't be able to find out until tomorrow, but perhaps you might be able to suggest what will be the simplest and easiest to implement. for now, i am not using anything fancy, just standard html tables.
 
I use ASP or PHP and server-side includes (SSI) to insert items common to more than one page. Both are equally easy to perform this function, and you can implement SSI using SHTML pages if the server is set up for them and you don't need to do any programming on the pages.

Lee
 
that sounds useful. do you know of a good webpage that provides a simple tutorial on how to do that in php?


 
great, thanks trollacious. i know one way 'include' can do what i originally intended. which is great!


however it might be able to do what i was hoping to do after i thought more elaborately about it.

let's say i have a file called template.php. this serves as the template for each webpage. the only thing differing across each page is text that is embedded into this template.

then if in template.php i have a line

<?php include("text_A.php") ?>

i could insert a file text.php which is just text surrounded by <html><body> text </body></html>.

but in order to do what i want, i need a way to be able to click a link (on a separate page) which inserts the specific text.php into the include function in template.php.

does it make sense what i am trying to do? is there a better way than what i am suggesting?

thanks!




this way i only need one template file, and a bunch of text files wrapped in <html><body></body></html>.
 


sorry, neglect the previous post of mine and read this one. i don't see how to edit posts and there are some mistakes above.

____________

great, thanks trollacious. i know one way 'include' can do what i originally intended. which is great!


however it might be able to do what i was hoping to do after i thought more elaborately about it.

let's say i have a file called template.php. this serves as the template for each webpage. the only thing differing across each page is text that is embedded into this template.

then if in template.php i have a line

<?php include("text.php") ?>

i could insert a file text.php which is just text surrounded by <html><body> text </body></html>.

but in order to do what i want, i need a way to be able to click a link (on a separate page) which inserts the specific text.php into the include function in template.php.

does it make sense what i am trying to do? is there a better way than what i am suggesting?

thanks!




 
Here's the approach I use. I create the top of the page in a PHP file, then include that on the individual page that has the content unique to it. I also create the bottom of the page the same way and include that at the bottom of the page. The "templates" are the top and bottom includes.

individualpage1.php
Code:
<? php
$title = 'Page 1';
include("pagetop.php") 
?>
<- page contents here ->
<?php include("pagebottom.php") ?>

pagetop.php
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title><? php
echo $title;
?></title>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
<- buttons and other top of the page contents here ->

pagebottom.php
Code:
<- bottom of the page contents here ->
</body>
</html>

Lee
 
i gotcha. i realize now i was thinking too restrictively about needing to have complete structures in the include function, but that's great that i can be incomplete text.

this completely addresses what i wanted to be able to do.

many thanks!

it's nice when thing can be so simple.
 
You could also use the a parameter in the ULR of your links lie so, to include the piece of text you want to insert into the tmeplate:

Code:
<a href="template.php?page=welcome">Welcome</a>
<a href="template.php?page=products">Products</a>
...

Then in your template page you can do:

Code:
if($_GET['page']=="welcome"){
include("welcome.txt");
}
if($_GET['page']=="product"){
include("products.txt");
}

If your template is a complete html page with all the parts, then you're included files don't need to have all the parts. They can just be text, or actual html, but don't need to be complete html pages with <html><header>.. etc tags, since the template already has those.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
ahh, that's very cool, thank you for this!

i'll give it a try.


this is great, you both have been quite helpful. this will be a great deal of help with a lot that i am working on

thanks!
 
Another quick note, with xHTML and trying to be semantically correct. Tables are for tabular data.

I'm guessing that the table on each of your pages is either masthead, layout or nvigation. Masthead and layout should be done by using div tags at logical divisions and using CSS to position. Navigation is semantically a list of links and should be a order list (ol) or an unordered list (ul) with CSS to control the look and feel.

Also, I generally go the other way, and include the template in the file within the HTML page

Code:
<?php
  page = '...';
  require_once('template.php');
?>

Code:
<html>
  <head>
    <!-- Title and meta data-->
    <!-- Style and scripts -->
  </head>
  <body>
    <!-- navigation -->
  </body>
</html>

If you do it the other way, you can clean up the address in the .htaccess file and mod_rewrite the URLs to be friendlier.

[plug=shameless]
[/plug]
 
tables for layout. i'll admit i have been kinda lazy about converting. but i need to redo everything now (because of a mishap, hence my asking here how to do it better and more efficiently), so i have been planning to restructure things. i will redo it with div. i do wish to try to do this more properly, so thank you for your comments here. i have recently started using ordered lists, so that's good.

as far as the latter, i'll have to think about it some more.
thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top