Skip to main content
September 17, 2009
Question

Can a cfmenu be closed in a cfif?

  • September 17, 2009
  • 1 reply
  • 1824 views

When I try to conditionally close a cfmenu with a cfif tag I get the following error...

The tag <cfif>, on line 12, column 4, requires an end tag.
The <cfif> tag requires an end tag to nest within <cfmenu>, which began on line 10, column 4.

The CFML compiler was processing:

    * The body of a cffunction tag beginning on line 7, column 2.
    * The body of a cffunction tag beginning on line 7, column 2.
    * The body of a cffunction tag beginning on line 7, column 2.


The error occurred in C:\ColdFusion8\wwwroot\HMC\cfc\testnav.cfc: line 12
Called from C:\ColdFusion8\wwwroot\HMC\Nav.cfm: line 18
Called from C:\ColdFusion8\wwwroot\HMC\index.cfm: line 10

10 :   <cfmenu bgcolor="##443266" type="horizontal" selecteditemcolor="##7C768B">
11 :   <cfset linksRead += 1>
12 :   <cfif linksRead GTE amountOfLinks>
13 :    </cfmenu>
14 :   </cfif>

As you can see the </cfif> is clearly there.

    This topic has been closed for replies.

    1 reply

    Inspiring
    September 17, 2009

    I think your error message kind of answers your question, eh?  But to confirm: no, one cannot do that.

    A CFML code needs to be syntactically complete at compile time, so one cannot control the code composition at runtime.  You have to bear in mind that the CF application server is not actually executing the CFML code in your files as you see it, the code is compiled first, then it is run.  So there cannot be runtime decisions being made as to how the code is written, as the code needs to be written and compiled before it is run.

    Make sense?

    --

    Adam

    September 17, 2009

    Yes, but I was hoping maybe I made a mistake elsewhere that would cause such an error. I am just frustrated that I can't seem to recursively populate a cfmenu.

    Inspiring
    September 17, 2009

    I think you should be approaching that problem from the perspective of already knowing if you're going to need the submenu before you get to the <cfmenu> tag, rather than how you seem to be doing it (which I don't follow the logic of, admittedly).

    I'll try to mock up some sample code, because code is probably easier to follow that some contorted narrative which I cannot work out how to articulate ;-)

    --

    Adam