字符串内的ColdFusion cfif求值

字符串内的ColdFusion cfif求值,coldfusion,Coldfusion,我有一个链接,可以用一些变量调用同一页面,但我只想在满足条件的情况下发送其中一个变量 <a href="testing.cfm?"<cfif checkMonth>"theday=#theday#&"</cfif>"themonth=#themonth#&theyear=#theyear#&checkMonth=#checkMonth#"> 这是代码。 我不希望为每个条件写两行。这可能不可能,但我只是想问一下。您可以这样做: ur

我有一个链接,可以用一些变量调用同一页面,但我只想在满足条件的情况下发送其中一个变量

<a href="testing.cfm?"<cfif checkMonth>"theday=#theday#&"</cfif>"themonth=#themonth#&theyear=#theyear#&checkMonth=#checkMonth#">

这是代码。
我不希望为每个条件写两行。这可能不可能,但我只是想问一下。

您可以这样做:

urlVariables = "dummyVariable=1";
urlVariables &= condition goes here ? "&Variable="#something#" : "";
etc

<a href="somewhere.cfm?#urlVariables#">link</a>
urlVariables=“dummyVariable=1”;
urlVariables&=条件在这里?“&Variable=“#某物#”:”;
等

您正在向字符串中添加不必要的
。一旦你移除了这些,下面的方法就可以了

<a href="testing.cfm?<cfif checkMonth>theday=#theday#&</cfif>themonth=#themonth#&theyear=#theyear#&checkMonth=#checkMonth#">

您可以编写

跳过引号(如Matt所说)-您可能还需要
#变量。日期#
,除非您已经在输出中。