Reputation: 821
I have a cfm page with html and css, needed for an email template. I have a sender.cfm file, which will include the template file and dynamically replace variables in the template file.
Below is a part of the template file
<td valign="top" align="left" style="padding:0 0 10px 0;">
<p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; line-height:18px; margin:8px 10px 10px 0; padding:0; color:#102044;">
[INSERT QUESTION 1]
</p>
</td>
Now in the sender file, I have a cfquery which is fetching the questions. I am doing something like this:
<cfsavecontent variable="questions">
<cfoutput><strong>#get_ques_text.questiontext#</strong></cfoutput>
</cfsavecontent>
<cfinclude template="weekly_template.cfm">
<cfset nl_template = replaceNoCase(nl_template, "[INSERT EMAIL TITLE]"
, "WEEKLY EMAIL") />
<cfset nl_template = replaceNoCase(nl_template, "[INSERT QUESTION 1]"
, questions)/>
I want to be able to get the list of all the questions in the cfsavecontent
variable. However, in the code above, I am only getting the first one. Any ideas why?
Upvotes: 0
Views: 1701
Reputation: 29870
If you reference a query value just as queryName.columnName
, then you are referencing one of:
depending on the context. In the context you're doing so - where CF is expecting a string - you'll just be getting the first row's value for that column.
If you want to iterate over the whole query, you need to tell ColdFusion that, via:
<cfloop query="yourQuery">
In your case, something like this:
<cfsavecontent variable="questions">
<cfloop query="get_ques_text">
<cfoutput><strong>#questiontext#</strong></cfoutput>
</cfloop>
</cfsavecontent>
Upvotes: 2