Skip to main content
Participant
November 20, 2014
Question

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

  • November 20, 2014
  • 1 reply
  • 169 views

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>">

    This topic has been closed for replies.

    1 reply

    Carl Von Stetten
    Legend
    November 20, 2014

    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.