moey moey - 1 month ago 20
PHP Question

Dreamweaver Templates Equivalent

I have been using Dreamweaver to build several sites. In particular, I utilize its templates to manage consistent layout / design throughout each site.

In a nutshell, it works like this:


  1. Create a template, for example:

    • <html><body><h1><!-- Marked as editable region. --></h1></body></html>


  2. Create a new page based on the template

    • <html>body><h1>Hello World!</h1></body></html>




So, if I need to change h1 to h2, I'd simply edit the template and all pages based on it will get updated automatically: simple. The question is how do I do this without depending myself on a proprietary application like Dreamweaver?

I am hoping a simplest possible solution. By simplest I mean, I hope I don't need to build a CMS or something. :)

Thanks!

Update:
Can we do this using e.g. PHP?

Answer

There are tones of several ways to do what you want.

Let's start from the Apache level:

In case your web site run under apache you can use a module called SSI. SSI Stands for Server Side Includes. This is the simple way if you like to create template like web sites with HTML. The method allows you to split you web page into several files and then the server will compose all these into one page. So you can have in example a header.html footer.html sitebar.html about_us.html and when you call the about_us.html the server will load also the other three files into that one.

Using PHP require(_once) or include(_once):

PHP have four commands that allows the developer to load external php files into the current working file. So in example you can have the files header.php, footer.php about_us.php. and into about_us.php you can include the external files. Consider that as an example:

header.php

<html>
    <head>
        <title>My page title</title>
    </head>
    <body>

footer.php

    </body>
</html>

about_us.php

<?php
    require_once('header.php');
?>
Enter here HTML for your about us page
<?php
    require_once('footer.php');
?>

Using a template Engine:

You can use a template engine like smarty. That engine requires PHP and is somehow difficult to use it. This is the most famous template engine for a long time now.

Using a programming language framework:

You can use a programming language framework, such us CakePHP that allows you to split your theme and create your own theme.

This list can be a really long. For now I thing you are ready to go with the most famous methods for templates ;)