How to call things in {tags} like in a CMS in classic ASP

Hi Experts,

In PHP CMS kits i've seen code put in between brackets and the site then calls that specific feature. I think this would be a nice thing to add to my custom classic ASP CMS site. So for example i'd like to have CMS HTML content but the client could add {contactform} and the contact form would show there. How can this be done in classic ASP? Some example code would be ideal.

Thanks and happy 2012!

/ Tobzzz
LVL 11
tobzzzAsked:
Who is Participating?
 
nap0leonCommented:
Presume you have a webpage that says simply "Hello {Firstname} {Lastname}".
Let's also presume that you already know that you should replace {Firstname} with "John" and {Lastname} with "Smith". (Instead of names, you could be replacing {contactform} with HTML for a contact form, etc.)

<%
dim FirstName,LastName,PageText,outputText
FirstName = "John"
Lastname = "Smith" 
PageText = "Hello {firstname} {lastname},"
'PageText = "Hello <font color=red>{firstname} {lastname},</font>"

outputText = PageText
outputText = Replace(outputText,"{firstname}",FirstName)
outputText = Replace(outputText,"{lastname}",LastName)
%>
<html>
<body>
<h1><%=outputText%></h1>
</body>
</html>

Open in new window


In practice:
1- FirstName and LastName would be values you have to look up from somewhere.  Perhaps they are page level variables, or you fetch them from a database or querystring, etc.
2- PageText is the template text (or HTML: uncomment line 6 to verify that the HTMl you place in PageText is processed and not displayed as text)

Caution on #2: If you want to place large sections of HTML onto the page, it gets tricky... you need to make sure your template does not contain any single-doublequotes (e.g., <font color="red">) since that will break the ASP.  They need to be double-doublequotes (e.g., <font color=""red"">).
0
 
David Johnson, CD, MVPOwnerCommented:
You need to elaborate on your question. perhaps some pictures of what you have and what you want would be beneficial. As it stands we have really no idea of what you really are looking for.
0
 
neeraj523Commented:
Dear Tobzzz

this is a very common concept being used through industry giving ability to create mail merge type of feature. Here, through code, we replace a specifically formatted keyword (ie {FirstName} or ~FirstName~ etc) with a value coming from database or preconfigured in the code.

For example, a non technical user want to send an email to his clients added in db with a personalized message, he will have ability to create mail template using keyword like

Dear {FirstName} {LastName}

where in code, you can replace {FirstName} and {LastName} with the values from database for the target customers before actually sending the email.

Let me know if you need further specific help in this regard..

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
tobzzzAuthor Commented:
HI neeraj523,

Yes this is exactly what I want to do but I do not know how to code it. It is essentially a replace feature, as you say and it is replacing it with things from the database. Please advise on how to code it and if you have any code sample or site references that would really help!

Thanks!

/ Tobzzz
0
 
sammySeltzerCommented:
Actually, asp tags are more like <%fieldname%>

If you wish to learn asp, go here:

http://www.w3schools.com/asp/asp_examples.asp

0
 
neeraj523Commented:
Dear Tobzzz

Does example given by nap0leon works for you ? DO you need further help on this question ?
0
 
tobzzzAuthor Commented:
Great example code - I will apply to the context of what I want to do with my new CMS - thanks nap0leon!

Also thanks to neeraj523 for the assist.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.