gpt4 book ai didi

coldfusion - 如何包含 ColdFusion 代码但不对其进行处理?

转载 作者:行者123 更新时间:2023-12-03 10:02:32 25 4
gpt4 key购买 nike

我正在使用 ColdFusion 8。

我正在创建一些代码来创建一个文件夹并插入一个文件。该文件稍后将由人工进行调整。

我这样创建目录:

<cfdirectory action="create" directory="#LOCAL.PathToCreate#">

接下来,我需要创建一个名为 index.cfm 的文件。现在,需要进入 index.cfm 文件的内容在 Test-21-index.txt 中。我这样创建内容:

<cfsavecontent variable="LOCAL.MyContent">
<cfinclude template="Test-21-index.txt">
</cfsavecontent>
<cffile action="write" file="#NewTreatmentPath##LOCAL.NewFile#" output="#LOCAL.MyContent#" nameconflict="overwrite">

Test-21-index.txt 的内容中有 ColdFusion 代码。我遇到的问题是,当我包含文件 Test-21-index.txt 时,正在运行 ColdFusion 代码。

如何将代码创建为在文件创建期间不运行的文本文件?

更新 ~ 有这么多工具可用于实现我的解决方案,我只需要正确的组合。我没有使用 cfsavecontent 读取文件,然后写入文件,而只是复制了文件。啊。那太容易了。

<cffile action="copy" source="#CurrentDirectory#\#LOCAL.FileToInclude#" destination="#NewTreatmentPath#\#LOCAL.NewFile#">

最佳答案

除了使用 cfinclude,您还可以使用 cffile 读取文件,然后将其内容输出到 cfsavecontent 标记中:

<cffile action="read" file="test-21-index.txt" variable="fileContent" />

<cfsavecontent variable="LOCAL.MyContent">
<cfoutput>#filecontent#</cfoutput>
</cfsavecontent>

<!--- or even <cfset LOCAL.MyContent = fileContent /> --->

<cffile action="write" file="#NewTreatmentPath##LOCAL.NewFile#" output="#LOCAL.MyContent#" nameconflict="overwrite">

代码未经测试,但我认为它应该可以工作。不过,我相信您需要以稍微不同的方式计算出 test-21-index.txt 的路径。

关于coldfusion - 如何包含 ColdFusion 代码但不对其进行处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11298091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com