3 Replies Latest reply on Jul 10, 2007 4:07 PM by c2345780293578032945

    Using <cfif> within <cfdocument>

      Using <cfif> within a <cfdocument> works ok unless it is within a variable. The following code fragment:

      <cfset var = "<cfif 1 eq 1>True part<cfelse>False part</cfif>">
      <cfdocument format="pdf" filename="test.pdf">
      1: #var#<br>
      2: <cfif 1 eq 1>True part<cfelse>False part</cfif>

      Results in generated PDF:

      1: True part False part
      2: True part

      That is, if the <cfif> is written out in full within the <cfdocument> it works properly, but if it is within a variable, both true and false parts get put into the generated PDF.

      How do I get the <cfif> to work properly when it is within the #var#?

      Thanks, Chris Veness
        • 1. Using &lt;cfif&gt; within &lt;cfdocument&gt;
          BKBK Adobe Community Professional & MVP
          It has nothing in particular to do with cfdocument. It is that you practically disable a tag when you pass it as part of a string. Coldfusion ignores it. For example,

          <cfset myVar = "<cfif 1 eq 1>True part<cfelse>False part</cfif>">

          simply sends the text "<cfif 1 eq 1>True part<cfelse>False part</cfif>" to output. I usually left the story there.

          However, Adam Cameron once made an important addition. Browsers are designed not to interprete or render tags they don't know. Since they don't know <cfif> or <cfelse>, they will ignore them. Hence, a browser will only display the text True partFalse part.

          • 2. Re: Using &lt;cfif&gt; within &lt;cfdocument&gt;
            Level 7
            > However, Adam Cameron, once made an important addition.

            Good god! I'm being cited.

            The problem with the OP's code is that the <cfif> is being generated at
            runtime, and any CFML code one expects to execute needs to be there at
            COMPILE time. CFML is not executed at runtime, so one cannot generate CFML
            at runtime and hope for it to execute. That's not how it works. And even
            if it was, one cannot expect it to be interpretted simply by *outputing*
            it. As BKBK said: all you're doing is sending a string to the browser (or,
            in this case, the PDF generator) which happens to have some CFML in it.

            You need to revise your logic / approach.

            • 3. Re: Using &lt;cfif&gt; within &lt;cfdocument&gt;
              c2345780293578032945 Level 1
              Thanks guys. Back to square one, with rather improved understanding, and a lesson learned for next time!