Skip to main content
Inspiring
March 13, 2009
Answered

Using conditional statements stored inside a variable

  • March 13, 2009
  • 5 replies
  • 893 views
I'm trying to store the body of different emails inside of my database to use in email sent with cfmail. The content of the emails has conditional statements using cfif and other variables based on a query running. If I set the content as a variable and then place that inside of the cfmail tag it does not process the cold fusion code. Is there a way that I can process this code so that the final output is what is placed within the cfmail tag or is it not possible to do what I'm trying to accomplish? Thanks in advance for any ideas.
    This topic has been closed for replies.
    Correct answer Newsgroup_User
    yes, that is what you need to do. it is actually mentioned in the
    documentation.

    the reason you need <cfoutput> tags inside the included file is because
    cf processes that file separately from the page that includes it.

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/

    5 replies

    Newsgroup_UserCorrect answer
    Inspiring
    March 18, 2009
    yes, that is what you need to do. it is actually mentioned in the
    documentation.

    the reason you need <cfoutput> tags inside the included file is because
    cf processes that file separately from the page that includes it.

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Inspiring
    March 17, 2009
    Placing <cfoutput> tags at the start and end of the #form.body# gave me the desired output. Is there a reason that these need to be inside the variable and not just surrounding the included file that is inside the cfsavecontent tag?
    Inspiring
    March 17, 2009
    It appears to be a problem with the cfsavecontent section of code as doing a cfdump of the textbody variable displays the original cfml code that is being sent to the cfsavecontent tag.
    Inspiring
    March 17, 2009
    Here is a sample taken from the text file. The output created by the cfsavecontent tag is identical to the text file.
    Dear <cfif IsDefined(GetData.strFirstName) AND GetData.strFirstName IS NOT "">#GetData.strFirstName#<cfelse>Member</cfif>,

    Thank you for joining xxxxxxxxx. We're glad to
    have you as a member and appreciate your support. Your membership
    application has been processed and your member packet will arrive soon.

    Your new membership number is #GetData.strCustomerID#. This number is useful
    when buying product from our online store, renewing your membership or
    contacting us with questions or comments.
    <cfif GetData.ExpirationDate IS "9999-12-1">We are especially grateful for your commitment to xxxxxxxx
    through your Life Membership.<cfelse>Your membership is current through #DateFormat(GetData.ExpirationDate, "MMMM YYYY")#.</cfif>
    Inspiring
    March 13, 2009
    You could generate the email message content within a CFSAVECONTENT tag, then save the content to your database and use it as the body of your email.
    Inspiring
    March 16, 2009
    Thanks for pointing me in the direction of cfsavecontent. I'm writing the cfml in the database to file and then using cfinclude to use that file in cfsavecontent. My conditional statements are working but the variables that are based off of a database query are not. Sample code is attached. Any ideas?