Search code examples
coldfusioncoldfusion-10cfmllucee

How to populate a template string in CFML


Forgive the newbie question here, but I am trying to allow for custom variables in a string that I would pull from a query, and replace those with results of another query. So to simplify it, I would need something like this...

<cfset mystring = "This is my %firstname% and this is my %lastname%.">

Then suppose I had query results of MyQuery,first and MyQuery.last, I would like the most efficient way to replace the %firstname% and %lastname% in mystring with the query results.

Any help/example would be so appreciated!

Thanks.


Solution

  • Are you looking for replaceNoCase()?

    <cfset myNewString = replaceNoCase(myString, '%firstname%', myQuery.first, 'all')>
    <cfset myNewString = replaceNoCase(myNewString, '%lastname%', myQuery.last, 'all')>