Solved

Using Curly Brakets To Represent Code Snippets

Posted on 2009-05-07
2
364 Views
Last Modified: 2012-05-06
Not sure if im going to be able to accomplish this but here goes anyway..

at the minute i have a rich text editor which allows users to type in text and bold, italic, colour etc and they they click the save button it posts to a script which then takes the HTML output from the rich text editor and saves the HTML to a field in the DB, a basic CMS system for content on a web page.

My question is this...

When i output the html on a display webpage (not in the rich text editor) i basically just fetch a recordset for that page and Response.Write the HTML field to the browser.

i would like to be able to define some fixed commands within the HTML such as:

{CustomerFirstName}
{CustomerLastName}
{CustomerAddress}

The idea is that if someone was typing into the rich text editor a sentence and they wanted to include a dynamic value into a certain place they would just create the sentence as such:

Dear {CustomerFirstname} {CustomerLastname},

Thank you for your order, it will be dispatached soon to your home address of:
{CustomerAddress}

When the customer webpage is run and it puls the HTML from the DB, it recognises the fixed command and inserts the correct value - basically like a mail merge in word.

Does anyone have an ideas of how to acomplish this as simply as possible?

Thans,
Carl
0
Comment
Question by:net-workx
2 Comments
 
LVL 8

Accepted Solution

by:
Bobaran98 earned 500 total points
ID: 24332328
Sure, this should be pretty easy.  I'm assuming you can query your DB and generate a string variable with the HTML code, and that you can also get your replacement values into string variables to.  Building on that, check out my code below:

Dim htmlFromDB as String
Dim fNameReplace as String
Dim lNameReplace as String
Dim addressReplace as String
 
'insert code here for assigning
'  values to above variables
 
Dim newHtml as String
 
newHtml = Replace(htmlFromDB, "{CustomerFirstname}", fNameReplace)
newHtml = Replace(newHtml, "{CustomerLastname}", lNameReplace)
newHtml = Replace(newHtml, "{CustomerAddress}", addressReplace)

Open in new window

0
 

Author Comment

by:net-workx
ID: 24336368
Excellent!

I didnt even think about doing it that way... things are so simple when you have someone else look at them!

Final code attached below for future use.  I can now add more fixed code snippets to whenever i want.

Thanks for your prompt solution to this question!

Carl
emailBody = RSemail("txtOrderReceivedBody")
emailBody = Replace(emailBody, "{FirstName}", txtFirstName)
emailBody = Replace(emailBody, "{LastName}", txtLastName)
emailBody = Replace(emailBody, "{OrderNumber}", intOrderID)
emailBody = Replace(emailBody, "{WebsiteAddress}", strWebAddress)
emailBody = Replace(emailBody, "{CompanyName}", strCompanyName)
emailBody = Replace(emailBody, "{Logo}", "<img src=""" & strWebAddress & strLogo & """>")

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question