views:

105

answers:

4

Hi Everyone,

Its been a while since I've done any hard core web design, so I have a question for you. I'm pretty sure that there is a feature of xhtml that allows you to create a template and include that template in your other xhtml pages. What I'm trying to do is create a "main links" template that allows any page to reference the main pages of the site. I figured a template would be better to use as it would allow easy editing of those links. If I were to just hard code them on all the pages, that would be a nightmare if I had to change something.

Btw, this site is only being done in xhtml, css and javascript. I could have used something more beefy like jsf, but I just didn't feel like it.

If anyone has any ideas on this, or suggestions on a better way to do it, it would be great.

Thanks, Robbie

+1  A: 

Do you mean something like asp.net master pages?

You can use AJAX or Serverside includes to include parts of your template. However, XHTML does not support this by default. You have to write code yourself. Most websites have a template which is included serverside.

In php you can do this:

page.php

<?php ob_start(); ?>
    your page
<?php 
    $content = ob_get_contents();
    ob_end_clean();
    $title="pagetitle";
    require("template.php");
?>

template.php

Use <?php echo $title; ?> where you want your title
Use <?php echo $content; ?> where you want your content
Time Machine
+2  A: 

You're probably looking at doing something with includes, which isn't a part of XHTML but rather a server-side technology such as PHP or ASP.

See this W3School's articles on PHP include() and require() and ASP Including files.

As far as I know, there isn't anything in XHTML, CSS and/or JavaScript that does what you want.

T Pops
Lame. I was hoping that wasn't the case. I guess I'll just have to relearn how to do jsf development.
Robbie
+2  A: 

You could extend the DTD with entities (as described at http://xml.silmaril.ie/authors/includes/) but you'll find browser support as poor as it is for XInclude.

If you want to use any kind of templating, then you need to look to other technologies which you can set up to output XHTML rather then doing anything intrinsic to XHTML itself (at least if you want to approach the problem sanely).

http://allmyfaqs.net/faq.pl?Include_one_file_in_another is a good summary of the options available.

David Dorward
A: 

If you really want to stay away from server side technologies that can offer the include functionality you want, perhaps you can find an IDE / editor that supports templates or includes or something similar. I have no experience with this myself, so I cannot recommend specific software, but I know that there are IDEs / editors that offer the functionality you look for.

Daan