Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using Curly Brakets To Represent Code Snippets

Posted on 2009-05-07
2
Medium Priority
?
370 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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…
Suggested Courses

824 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