Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Should ColdFusion <cfoutput> tags be placed inside other tags?

New Here ,
Nov 20, 2014 Nov 20, 2014

Should ColdFusion <cfoutput> tags be placed inside other tags?

Which of these examples is preferred?  Is the other acceptable?

ex. A: <cfoutput><img src="#imgurl#"></cfoutput>

ex. B: <img src="<cfoutput>#imgurl#</cfoutput>">

138
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 20, 2014 Nov 20, 2014
LATEST

Personally, I would choose example A as it is cleaner to read.  Also, if I needed to populate multiple attributes of the <img> or other HTML tag, wrapping each individual attributes value in <cfoutput> tags would be silly.

However, it really depends on personal taste and the context of the situation.  If possible, I try to avoid peppering a page with opening and closing <cfoutput> tags and instead wrap as much display code as possible in a single <cfoutput>.  Also, if you are outputting the contents of a query in a loop-like fashion ( <cfoutput query=""> ), then I'd only have one <cfoutput> tag (unless I was using the grouping feature of cfoutput, in which case I'd have nested <cfoutput> tags).

-Carl V.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources