2016-09-28 52 views
0

我有一個鏈接,回憶與一些變量相同的頁面,但我只想發送一個變量只有當條件滿足。ColdFusion cfif評估字符串內

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

這是代碼。 我不想爲每個條件寫兩行。這可能是不可能的,但我只是想問。

+0

跳過報價(如馬特說) - 你可能還需要'#variables.theday#'除非你已經是輸出的內部。 –

回答

-2

你可以做這樣的事情:

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

<a href="somewhere.cfm?#urlVariables#">link</a> 
1

你增加不必要的"字符串。一旦你刪除以下應該工作。

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

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