3

我有一个保存表格的 cfsavecontent 标记。后来我使用 cffile 将保存的内容写入文件。当我查看那个文件时,我看到<td>表格中的标签后面插入了许多空行;</tr>并在标签后插入几行空行。(尽管它不会在代码<tr><td>&nbsp;</td></tr>在一行中全部显示的情况下做到这一点。)

目前我有一个包含其中两个表的文件。这些表在循环中生成,并使用 cffile append 创建输出文件。这个文件有 915 行,其中可能有 30 行是非空白的。我所有的后续代码都可以正常工作,但这只是测试数据。在现实世界中,我可能有 1000 个或更多表,而且我担心文件大小。

编码:

<cfset head1 = 'from = "moxware" '>
<cfset head2 = 'to = "#hrep.PersonEmail#" '>   
<cfset head3 = 'replyto = "#replyto#" '>
<cfset head4 = 'subject = "#subject#" '>
<cfset head5 = 'type = "html" '>      

<cfsavecontent variable = "abc">
  <cfoutput>
   #head1#
   #head2#
   #head3#
   #head4#
   #head5# >
    #xyz#
  </cfoutput>
</cfsavecontent>

<cffile action = "append"
    file = "/var/www/reports/moxrep/#reportout#.cfm"
    output = "<cfmail"
    mode = "777" >

<cffile action = "append"
       file   = "/var/www/reports/moxrep/#reportout#.cfm"
       output = "#abc#"
       mode   = "777"> 

<cffile action = "append"
    file = "/var/www/reports/moxrep/#reportout#.cfm"
    output = "</cfmail>"
    mode = "777" >

关于 xyz,我正在从文件中读取它:

      <cffile action = "read"
      file   = "/var/www/reports/moxrep/#reportname#.cfm"
      variable = "xyz">

文件如下所示:

   <link rel="stylesheet" href="sample.css">
  <link rel="stylesheet" type = "text/css" href ="betty.css"/>
  <p style="margin-left:40px"><span style="font-size:14px"><span style="font- family:georgia,serif">Dear Customer,</span></span></p>

We were so pleased that you have signed up for one of our programs.&nbsp; Apparently you live in the city of {{1.&nbsp; Additionally we observe that your were referred to us by {{2.&nbsp; Below please find a listing of what you signed up for.</span></span></p>

<p style="margin-left:40px"><span style="font-size:14px"><span style="font-    family:georgia,serif">{{r</span></span></p>

<p style="margin-left:40px"><span style="font-size:14px"><span style="font-family:georgia,serif">Sincerely Yours,</span></span></p>

<p style="margin-left:40px"><span style="font-size:14px"><span style="font-family:georgia,serif">John Jones<br />
President<br />
XYZ Corporation</span></span></p>

该文件是由代码生成器创建的,而不是我,所以有点麻烦。稍后在代码中,我替换了以 {{ ; 开头的所有内容 特别是 {{r 被替换为表格,这就是额外空间的来源。

追加本身没有插入任何额外的行。

有谁知道是什么导致文件中这些额外的空白行?以及如何摆脱它们?

4

2 回答 2

0

您可以考虑在您的 cfsave 内容周围使用 cfprocessingdirective。CF 管理员中有一个设置可以普遍压缩或保留不必要的空白,“启用空白管理” - http://help.adobe.com/en_US/ColdFusion/9.0/Admin/WSc3ff6d0ea77859461172e0811cbf3638e6-7ffc.html。使用 cfprocessingdirective 的 suppressWhiteSpace 属性,您可以为特定页面或页面的一部分覆盖此设置。所以在你的情况下:

<cfprocessingdirective suppressWhiteSpace="true">
<cfsavecontent variable="myvar">....
...
...
</cfsavecontent>
</cfprocessingdirective>

可能会有所帮助。同样,为了确保在构建文本电子邮件时保留空白,您可以使用 suppressWhiteSpace="false"。

干杯,

于 2014-12-10T20:00:04.250 回答
0

贝蒂,如果你想避免空格,通常你需要小心地做这件事。特别是在查询中使用 cfoutput 会生成行。所以这段代码:

<table>
<cfoutput query="myquery">
  <tr><td>#col1#</td><td>#col2#</td></tr>

</cfoutput>
</table>

会产生额外的线条......但如果你这样做:

<cfsetting enablecfoutputonly="yes">

<cfoutput><table></cfoutput>
<cfloop query="myquery"><cfoutput><tr><td>#col1#</td><td>#col2#</td></tr></cfoutput></cfloop>
<cfoutput></table></cfoutput>

您将仔细控制允许附加到缓冲区的确切内容。enableoutputonly 完全按照它所说的去做......它不允许任何东西“进入缓冲区”,除非它包含在 cfoutputs 中。

希望这可以帮助。正如卡梅伦所说,您应该为此类问题粘贴代码。这就是答案通常所在的地方。

(您可能还需要尝试使用 cffile 的“addnewline”属性 - 取决于您的问题是否是文件末尾的一行)。


要回答有关添加 cfsetting 的问题...在您的情况下,您正在将 CF 代码写入一个文件,然后稍后执行(顺便说一句,这通常不是一个好主意:)。所以在你的第一个 Append 语句中:

<cffile action = "append"
file = "/var/www/reports/moxrep/#reportout#.cfm"
output = "<cfmail"
mode = "777" >

将“输出”更改为:

<cffile action = "append"
    file = "/var/www/reports/moxrep/#reportout#.cfm"
    output = "<cfsetting enablecfoutputonly=""yes""/> <cfmail"
    mode = "777" >

但是 Betty - 你仍然需要从你的 cfsavecontent 中删除换行符(如果这是你的空格的来源),因为它们实际上是在 cfoutput 中。此外,创建要插入的表的代码可能有问题 - 此处未列出。

最后,由于这是 cfmail,请查看这篇关于换行符的帖子,这可能会或可能不会产生影响 - 但至少可以为您提供更多信息 :)

http://www.coldfusionmuse.com/index.cfm/2006/4/12/cfmail.linebreak

于 2013-08-17T22:13:51.587 回答