ASP 101 - Active Server Pages 101 - Web04
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Getting Scripts to Run on a Schedule
The Top 10 ASP Links @
What is and Why Do I Need It?

Changing the default scripting language at the server level
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

A Simple Content Management System Tutorial

by Jesus Torres

Simple CMS

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:

  1. Create a Website template
  2. Create an MS Access Database for the Content
  3. Show you how to use the FileSystemObject to read a text file
  4. 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:


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 becalled "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
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 theURLparameter"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.:

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".


Click here to see the Template.

Click here to download all the files including the database (32 kb).

For more information about a commercial CMS based on this article click here.

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers