Copy link to clipboard
Copied
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>">
Copy link to clipboard
Copied
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.