by the same token you can also put the header and footer code into a single page called template.php with
in the middle. Then you just do this on every page.
$content = "pathtocontentpage.html";
and voila, the template echo the page set to content.
[edited by: jatar_k at 1:35 am (utc) on Sep. 29, 2003]
And in ASP...
<%@ Language=VBScript %>
<% Option Explicit %>
<!-- #include virtual="/Includes/header.asp" -->
add your content here
<!-- #include virtual="/Includes/footer.asp" -->
Very cool, jatar_k!
And then put all content into a database for even more control. I love the concept of dynamic sites.
Does anyone know the basic formula for Cold Fusion? In other words can you produce the above example in Cold Fusion?
BTW, I don't see a forum for Cold Fusion.
It would also be cool to see a Java example or any other language for that matter.
I've been doing something similar (using SSI) for quite some
time. Really speeds up creating new pages.
For those now familiar with doing the same using SSI :
title & meta stuff
<!--#include virtual="header.html" -->
<!--#include virtual="footer.html" -->
>>For those who want a dynamic site, start by changing index.htm to index.php
or if you're on *nix just add AddType application/x-httpd-php .php .htm .html to your htaccess file and parse html and htm files for php and keep your current extensions
Slight modification: if you change your header file so that it has the lines..
if (!isset($title') )
$title = 'My Web Site';
Then your not stuck with the same title on all your pages, because you can change it before the include like this..
$title = 'Contact Us';
I use this technique to change the title, section (h1) and page name (h2) on my pages.
|AddType application/x-httpd-php .php .htm .html |
Be aware that on a very busy site this will cause unneccessary load on the server, as it has to parse all html files before serving them. Even the ones without any php in them.
Probably not a big problem in most situations though.
I am not real familiar with PHP but can this type of dynamic generating also be combined with breadcrums and if so how?
>then put all content into a database for even more control
Would a MySQL or a flatfile database be the best way to go?
And...to INCLUDE an example in another language (excuse the pun).
Here is Cold Fusion. Create index.cfm
Title and metatags here
<CFINCLUDE TEMPLATE = "../includes/header.htm">
<CFINCLUDE TEMPLATE = "../includes/footer.htm">
And to finish off the languages, here is java (JSP):
<%@ include file="header.jsp" %>
content goes here
<%@ include file="footer.jsp" %>
|can this type of dynamic generating also be combined with breadcrums |
Just so happens that I have just published an automatic breadcrumb generator, see the Bag-O-Tricks II [webmasterworld.com] thread.
|Would a MySQL or a flatfile database be the best way to go? |
I would go with MySQL - it is well supported and it should always outperform a flat file db.
But don't create this kind of thing from scratch - there are plenty of existing Content Management Systems (CMS) available - many of them are open source and free to use.
Includes really are a time saver. If you have the ability you will save so much work.
echo "Content-Type: text/html"
cat << EOBODY
## --> content here - <--
Course you will need to keep all your pages in a ScriptAliased directory (or set up your webserver some other way so that it parses the script). Fast though - low overhead!
[edited: forgot the heredoc, duh.]
Hehehe, let me throw a wrench in the gears. Here is the FP way...
<!--webbot bot="Include" u-include="/navigation/left.asp" tag="body" -->
Alright, come and get me! ;)
P.S. Feeding data from a MySQL database.
pageone, you should be ashamed of yourself. ;)
|Would a MySQL or a flatfile database be the best way to go? |
Marcia, either works well it depends on what you have available to you. I have used both and very good results both ways.
If I had to pick though I would take mysql, more power involved. You can use db functionality in concert with of php functionality giving you the best of both worlds. If you are solely serving chunks of content it really doesn't matter too much.
I think that as things get more complex using built in sql functionality can take some of the weight from the scripting language.
don't includes prevent the header from returning a valid last-modified date and prevent caching? meaning every user has to load the page freshly, regardless of when he last saw it?
it also prevents googlebot from reading just the headers [webmasterworld.com] on your server to save time and bandwidth
i know it is possible with SSI if you use the .htm or .html extension by chmodding each page to 754.
but how does one get around this for a dynamic php site? so that the header returned a correct last modified date according to the content and/or the last update of the header.inc and footer.inc?
the last-modified date would still be on the file that includes the headers and footers or the template page.
contact.html is the page name and has the actual page content written into it. If the content of the page is updated the last-modified date will change.
contact.html includes the template(s) but the true page is contact.html.
I always use static page names for dynamic sites which is how the bots know about last-modified dates etc. This won't reflect changes to the site wide template but *shrug* there is never a perfect scenario. You could always change all your hard coded headers individually but that requires a lot more time.
A sidenote: Have you ever looked at what comes up in the browser if you directly request a .inc file? It is the code. I only use .inc.php or, for libraries, .lib.php and most of the time just .php and organized into directories that classify the files. This keeps users from being able to see my code.
so, you do what oilman does and use
|or if you're on *nix just add AddType application/x-httpd-php .php .htm .html to your htaccess file and parse html and htm files for php and keep your current extensions |
so that your html pages are parsed as php?
sorry for simple question, but this thread has got me thinking about an area in which i'd really like to know more
depends on the site but mostly, yes.
The same will stand true if you use a php extension.
|But don't create this kind of thing from scratch - there are plenty of existing Content Management Systems (CMS) available - many of them are open source and free to use. |
Don't create what kind of thing from scratch? A website? If so, wouldn't it be better to create your own from scratch? If not, please elaborate...
|And then put all content into a database for even more control. I love the concept of dynamic sites. |
One thing I still can't grasp about this...
Say you have multiple paragraphs, headers, etc. How do you put the content into a database and split it up on the page? I understand how to query information from a database, but I just can't see the need for putting the content from each individual website page into a database to pull out~ How does this work?
>>Say you have multiple paragraphs, headers, etc. How do you put the content into a database and split it up on the page?
madcat, I usually will have all the main body content formatted in the db(i.e. <p>s <h2>s, etc..). I will have a field for the title, which I will use for <title> and <h1>.
>>I just can't see the need for putting the content from each individual website page into a database
To me, the useful thing about storing the content in a db is that I only need one file to to display as many pages as I need. I can also change the layout in one shot, too. It keeps the file system nearly empty, whereas if you had a thousand page site it could get confusing.
|I usually will have all the main body content formatted in the db(i.e. <p>s <h2>s, etc..). I will have a field for the title, which I will use for <title> and <h1>. |
Ok, so bear with me on this. Say I have three pages:
page 1 > company info
page 2 > service info
page 3 > contact info
Each page will have a few paragraphs, and each page will have different titles of course. Not to mention different sized headings. Specifically, what would your fields look like, and how would the content look within its MySQL table cell- for i.e., how would it be formatted?
I'm assuming that you have one .html page that acts as a template pulling in the various elements like menus, footers, logos and headers > I'm still a bit cloudy about the content portion including the <p>'s, <h1>'s, images and other elements that normally go withing that content...how they're laid out in the db.
Any direction is much appreciated ^
In your example case, which seems like a business e-biz-card type site, I wouldn't even go dynamic. But I'm sure you were just using a simple example. The type of site I would build dynamically is one that changes constantly or grows on a regular basis, like an e-commerce or news site.
I'll use another example to better illustrate the benefits. Suppose you sell, well of course, Widgets. You start out selling only green, blue and red widgets. So you set up your database like so:
table 1: cats //categories for main nav
- field 1: cat_id //INT auto increment(a way to reference the cats)
- field 2: cat_name //i.e. Red Widgets, Green Widgets, etc...
- field 3: cat_text //intro text for each category
table 2: products
- field 1: product_id //item number
- field 2: prod_cat_id //what category it's in(cat_id)
- field 2: product_name
- field 3: product_description
- field 4: price
- field 5: stock //how many are in stock(optional, of course)
Now you can build your main navigation from the database by asking for all listings in cats(SELECT cat_id FROM cats). So when you decide to add purple and teal widgets in the future, all you have to do is add a row for each in the db and all your pages' navigation menus will now show them as well. You will point all the nav links to the same file, with a parameter at the end which will tell the landing page what to display(i.e. href="widgets.com/products.php?cat=2")
Now products.php will get the variable($cat) you sent along in the url and query the db for any product that belong in that category. Personally, I use a combination of cat_name and product_name to build my <title> and <h1> tags, but you could easily add more fields to the db if needed.
So once you get to the main content, you just display the product_description field, which would be a text field and would have all formatting already done.
<p>beautiful green widgets for sale...featuring</p>
<p>Get them while they're hot!</p>
Also, I name the associated image the same as the product_id, so I know I can reference it with the same variable I used to call the content.
Well, I need to go to bed...it's midnight here. I hope that made some sort of sense :) Also keep in mind that I'm no guru over here, so there may be flaws in my technique but maybe it'll help you picture the concept better.