Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to wrap an entire CFM page in a cfoutput tag

Tags:

coldfusion

I am placing a <cfoutput> tag around my entire <html> tag. The ColdBox best practice guide states "When you are creating view templates, try to always surround it with 1 cfoutput tag, instead of nesting them all over the place."

But I have on occasion seen errors pop up where a <script> block containing javascript code is within the <cfoutput> tag. This probably because Coldfusion sees a hash # and tries to parse it but it can't because its javascript.

So how does one get away with having a single <cfoutput> tag on a view page in which to place everything?

like image 746
volume one Avatar asked Jul 25 '14 13:07

volume one


2 Answers

I am not aware of any significant security or performance concerns in regards to wrapping an entire page in cfoutput. Of course, you'll always need to be aware to escape any pound signs by doubling them up any time you're inside a cfoutput.

The best practices in that ColdBox guide are geared primarily toward readability and reducing clutter on the page. If you have large sections of the page that you don't want to escape pound signs on or if you like to use cfoutput's grouping functionality, there's nothing wrong with breaking up your cfoutputs in a way that makes sense.

In the olden days of CF there might have been more overhead, but these days I can't imagine it being more than a few nanoseconds, and that's once at compile time.

like image 165
Brad Wood Avatar answered Nov 15 '22 12:11

Brad Wood


In my view files I tend to wrap all output in a single cfoutput tag.

You can escape # symbols in JavaScript, etc, by converting them to ##.

like image 38
Simon Bingham Avatar answered Nov 15 '22 12:11

Simon Bingham