如何强制评估存储在字符串中的cfif? [英] How do I force evaluation of a cfif stored in a string?

查看:198
本文介绍了如何强制评估存储在字符串中的cfif?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在数据库中存储coldfusion代码以用于cfmail的主题。存储的代码如下:

I am trying to store coldfusion code in a database to be used for the subject of a cfmail. The code stored is as follows:

"RE: <cfif myData.general.legalName NEQ """">  {{dotlegalname}}<cfelse>{{docketLegalName}}</cfif>,    
DOT## {{dot}}, Docket ##(s)   {{docketString}}" 

当我从数据库检索字符串时,我使用cfsavecontent来尝试评估它。

When I retrieve string from the database, I use cfsavecontent to attempt to evaluate it.

<cfsavecontent variable="subject">
 <cfoutput>#myData.email.subject#</cfoutput>
</cfsavecontent>

我也试过了

<cfsavecontent variable="subject">
     <cfoutput>#evaluate(myData.email.subject)#</cfoutput>
</cfsavecontent>

然后将所有{{}}替换为适当的值。

And then I replace all the {{ }} with the appropriate values.

但是,电子邮件的主题固执地拒绝包含已评估的cfif,而是显示cfif,如同它是一个字符串。

However, the subject of the email is stubbornly refusing to contain an evaluated cfif, and is instead showing the cfif as if it were a string.

任何想法?

推荐答案

动态评估您在运行时创建的代码的唯一方法是,一个文件,然后执行它。

The only way to dynamically evaluate code that you are creating at runtime is via writing it out to a file, and then executing it.

最简单的方法是在虚拟文件系统中写一个.cfm页面(可能将文件命名为UUID之后,它是唯一的),然后它在哪里你需要运行的内容。

The easiest way would be to write it a .cfm page in the Virtual File System (probably name the file after a UUID, so it's unique), and then it where you need to run the contents.

我通常不会倡导在运行时生成代码这样,但它可以是最优雅的

I wouldn't normally advocate generating code at runtime like this, but it can be the most elegant solution in some cases.

另一种方法是,不是将CFML代码存储在数据库中,而是有一组CFML电子邮件模板文件存储在目录中您的服务器,并且在数据库中,您只需记录需要通过cfinclude或cfmodule添加的模板。

As an alternative, instead of storing the CFML code in the database, you have a set of CFML email template files that get stored in a directory on your server, and in your database you simply record which template needs to be included either via cfinclude or cfmodule.

这篇关于如何强制评估存储在字符串中的cfif?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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