让我们考虑一下,以下HTML片段存储在名为OBJECT的列中名为CONTENT的数据库表中,该列包含动态XmlSearch表达式:
'<p style="margin: 0 0 10px;">Hello <cfoutput>#XmlSearch(LOCAL.xmlData,"/billing/invoice/cust_fname")[1].XmlText#</cfoutput>,</p>'
然后我有一些HTML模板到HTML页面,并在ColdFusion中进行了数据处理:
process-html.cfm
<cfquery name="contentQry">
SELECT "OBJECT" FROM content WHERE "ID" = 1
</cfquery>
<cfsavecontent variable="templatePage">
<cfinclude template="template.html">
</cfsavecontent>
<cffile action="write" output="#templatePage#" file="generated-page.html'#">
最后是一个HTML模板文件,其中包括从数据库中注入的动态数据:
template.html
...
<td id="editable-content"><cfoutput>#Evaluate(contentQry.OBJECT)#</cfoutput></td>
...
由于在Evaluate函数的表达式中存在HTML代码,这会引发编译器错误。
在包含HTML和CFML的情况下,有什么方法可以执行动态表达式(以字符串形式存储在数据库中)吗?
感谢您的建议。