The definition of a content management system (CMS)
is as diverse as all the people creating them, but at the very core of a CMS
is the concept of separating Website layout and design from content. By doing
this you provide a means for the Web Developer to do his job and not get bogged
down with endless requests for content changes/additions, more importantly
though, this empowers the non-Developer, (content creators) to update/create
their own web pages.
I will show you in this tutorial how to create a simple CMS. This tutorial
will do the following:
Create a Website template
Create an MS Access Database for the Content
Show you how to use the FileSystemObject to read a text file
Show you how to use the VBScript function Replace()
CMS Template - Part I
First we need to create a Website
template (how to do this is a tutorial to itself). You can use any HTML editor
out there (I personally prefer Dreamweaver MX). We want to create a modular
layout with the Name and Logo for our Website, a place for our Website
navigation and the content area:
CMS Template - Part II
In order to make this work, we will
create a template and use tokens as place holders for the content:
{%PageTitle%}
{%Content%}
Our Template should look like this:
CMS Content Database
We need to create an MS Access
database to store the Web Content. The one I created is called "SimpleCMS" and
the Table is called "WebContent":
CMS ASP Script
Now we will put it all together with the
ASP script. The script will be called "Default.asp". The first thing we do is
create new page in Dreamweaver and delete all the HTML, then create a
recordset:
Next we have to do some hand coding so hang on to your hats:
Code Part I
This is the code to read the contents of our Template file
(Template.htm):
<%
Page_Template = ""
Set objTemplate = Server.CreateObject("Scripting.FileSystemObject")
Set objText = objTemplate.OpenTextFile(Server.MapPath("Template.htm"),1,false)
Page_Template = objText.ReadAll
objText.Close
Set objText = Nothing
Set objTemplate = Nothing
%>
Code Part II
This is the CMS Code Part II where we read the Database table "WebContent"
based on the URL parameter "Page", if no URL parameter is specified we read from
the first record:
1. <%
2. MyWebPage = "That Web Page is not Found."
3. If Request.QueryString("Page") <> "" Then
4. rsContent.filter = "WebContent_ID = " & CStr(Request.QueryString("Page"))
5. End If
6. If Not (rsContent.eof or rsContent.bof) Then
7. MyPageTitle = (rsContent.Fields.Item("WebContent_Title").Value)
8. Page_Content = (rsContent.Fields.Item("WebContent_Text").Value)
9. MyWebPage = Replace(Page_Template,"{%Content%}",Page_Content)
10. MyWebPage = Replace(MyWebPage,"{%PageTitle%}",MyPageTitle)
11. End If
12. Response.Write(MyWebPage)
13. %>
First we determine if a URL parameter has been passed. The URL parameter
would be used to specify a particular page which would be stored in the
database, i.e.:
http://www.website.com/default.asp?Page=7
6. If we have not traveled to the end of the table without finding a record,
7. we proceed to read the Page Title from the field "WebContent_Title" and
8. the Page Content from the field "WebContent_Text".
9. Here we take the contents of Template (stored in the variable "Page_Template") and replace the token "{%Content%} with the contents of the field "WebContent_Text".
10. Here we take the contents of our Web Page (stored in the variable "MyWebPage" and replace the token "{%PageTitle%}" with the contents of the field "WebContent_Title".