执行coldfusion代码存储在字符串中动态? [英] Execute coldfusion code stored in a string dynamically?

查看:189
本文介绍了执行coldfusion代码存储在字符串中动态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个电子邮件正文作为字符串存储在数据库中,类似这样:

I have an email body stored as a string in a database, something like this:


这是一个电子邮件正文,不同的变量。尊敬的#name#,< br /> 请与#representativeName#联系以了解更多详情。

This is an email body containing lots of different variables. Dear #name#, <br/> Please contact #representativeName# for further details.

我使用存储过程从数据库中取出这个字段,然后我想在coldfusion端评估它,因此,它将插入name变量的值,而不是#name#。

I pull this field from the database using a stored proc, and then I want to evaluate it on the coldfusion side, so that instead of "#name#", it will insert the value of the name variable.

我已经尝试过使用evaluate,但是只有当只是一个变量名时,它才能工作。它会抛出一个错误,因为其他文本。

I've tried using evaluate, but that only seems to work if there's just a variable name. It throws an error because of the other text.

(我不能只使用占位符和一个find / replace这样 - 在Coldfusion字符串中解析变量,因为将它存储在数据库中的整个要点是变量用于构建字符串是动态的。例如,在一种情况下,名称字段可以称为名称,在另一种情况下可以是firstName等)

(I can't just use placeholders and a find/replace like this - Resolving variables inside a Coldfusion string, because the whole point of storing this in a database is that the variables used to build the string are dynamic. For example, in one case the name field can be called "name" and in another it could be "firstName", etc.)

推荐答案

我将循环遍历每个#variableName#引用并将其替换为已评估的版本。

I would loop over each #variableName# reference and replace it with the evaluated version.

正则表达式将能够找到他们所有,然后一个循环,他们所有的,只是评估他们一个一个。

A regex will be able to find them all and then a loop to go over them all and just evaluate them one by one.

这篇关于执行coldfusion代码存储在字符串中动态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆