tags:

views:

92

answers:

4

Hi, I'm being forced/payed to work on a Legacy ColdFusion project (I'm an usual C# programmer) and one peculiarity with CF is that they have they're own tags that are supposed to blend with HTML (bad bad decision, IMO, since it just confuses the hell out of me even with the "starts with cf rule).

Besides this, they have the # character to indicate the start of CF "territory" much alike <% in ASP.Net or $ in Spark or so many equivalents. But this only gets parsed if inside a tag.

My question is: Is there a problem with opening one tag in the begining of the file and closing it, against using only when i'm going to use the # character?

To illustrate here's some code:

<cfoutput>
    Some text #SomeVar# Some text.<br />
    Some Images some other things #AnotherVar#
</cfoutput>

Against:

Some text <cfoutput>#SomeVar#</cfoutput> Some text.<br/>
Some Images some other things <cfoutput>#AnotherVar#</cfoutput>

Granted, this is might seem trivial for small content but i'm talking about a whole page.

+1  A: 

It should not be a big issue but be careful using hex-valued colors, you'll need to escape those with an extra #. If it was me, I would try to break down those huge chunks of content into smaller pieces. Let HTML, JS, Flash and CSS do their jobs and use CF for the server side.

Don
Yes, i'm aware. Just consider this a bonus for making me use CSS as it should.
Felipe Leusin
+6  A: 

Depending on the page contents, either is fine. There may be a performance impact (minor) by putting all of your page inside the CFOUTPUT tag, because the CFML engine needs to parse and scan the contents of the tag for executable code. Outside of the CFOUTPUT tag, the CFML engine can ignore the page as static content.

If you have CSS and HTML code that uses pound signs (for example named anchors or Hex color codes), you need to escape all pound signs (by adding a second one like "##") when within a CFOUTPUT. Because of this, I generally only put the CFOUTPUT around code I specifically want the CF engine to run.

That said, the CFML engine pays a bit of a performance penalty for constantly opening and closing the CFOUTPUT. If you're looping over come content, put the CFOUTPUT around the entire loop, rather than opening and closing it in each iteration of the loop.

Also, if you're having trouble knowing what code is CFML and what isn't, you might want to get a better IDE/editor for CFML like CFEclipse. It color codes the tags and lets you see the difference between CFML and HTML tags immediately. It's open source.

bpanulla
+2  A: 

One problem you might find is that cfoutput is often used to display queries and they can not be nested inside of other cfoutput tags. So this will cause a 'Invalid tag nesting configuration' error

<cfoutput>
  <cfoutput query="qFriends">
    <li>#qFriends.fname# #qFriends.lname#</li>
  </cfoutput>
</cfoutput>
Nick
Yeah, although you can use cfloop, but unfortunately they still have not allowed you to use the group attribute with cfloop. I find this very odd.
Tyler Clendenin
A: 

If you want to put cfoutput at the beginning and end of the page, you have to use double sign ## for colors value.

ppshein