Solved

Using Curly Brakets To Represent Code Snippets

Posted on 2009-05-07
2
360 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now