Skip to content

Instantly share code, notes, and snippets.

@sublimecoder
Last active June 24, 2016 19:21
Show Gist options
  • Save sublimecoder/e0102664b6765d7f79ab to your computer and use it in GitHub Desktop.
Save sublimecoder/e0102664b6765d7f79ab to your computer and use it in GitHub Desktop.
<!---Start Function to look through arguments and replace special variables with Road Map variables. --->
<cffunction name="fillInTemplate" access="public" returntype="string" output="false">
<cfargument name="map" type="struct" required="true" />
<cfargument name="template" type="string" required="true" />
<cfset var str = arguments.template />
<cfset var k = "" />
<cfloop list="#StructKeyList(arguments.map)#" index="k">
<cfset str = ReplaceNoCase(str, "{{#k#}}", arguments.map[k], "ALL") />
</cfloop>
<cfreturn str />
</cffunction>
<!--- End function --->
<!--- Template text to be used in the function.
The information comes from the Custom Template query. You should set this up to query the database where you want to pull the template text from.--->
<cfquery name="customTemplate" datasource="#application.DSN#">
SELECT custom_email,
custom_donor_pdf,
custom_recipient_pdf
FROM custom_templates
</cfquery>
<!--- set the query vaules to simplified variables for readability. --->
<cfset emailTemplate = customTemplate.custom_email>
<cfset donorPdfTemplate = customTemplate.custom_donor_pdf>
<cfset recipientDonorPdfTemplate = customTemplate.custom_recipient_pdf>
<!--- End templates--->
<!--- Road Map Structure that references variables that will be replaced in the template.
You must define all special variables that the user will use here.
Below we are setting the special variables to the Donation Query's Values.
--->
<cfquery name="donationQry" datasource="#application.DSN#">
SELECT first_fname,
last_name,
recipient_first_name,
recipient_last_name,
donation_type,
donation_ammount,
honoree,
event_name,
organization_name,
tax_id
FROM dontation_config
</cfquery>
<cfset map = structNew()/>
<cfset map["First Name"] = donationQry.first_fname />
<cfset map["Last Name"] = donationQry.last_name />
<cfset map["Recipient First Name"] = donationQry.recipient_first_name />
<cfset map["Recipient Last Name"] = donationQry.recipient_last_name />
<cfset map["Donation Ammount"] = dollarformat(donationQry.donation_ammount) />
<cfset map["Donation type"] = donationQry.donation_type />
<cfset map["Honoree"] = donationQry.honoree />
<cfset map["Event Name"] = donationQry.event_name />
<cfset map["Date"] = dateformat(now(), "mmmm dd, yyyy") />
<cfset map["Organization Name"] = donationQry.organization_name />
<cfset map["Tax Id"] = donationQry.tax_id />
<!---End Struct--->
<!--- Set variables with completed Template information. --->
<cfset filledEmail = fillInTemplate(map, emailTemplate) />
<cfset filledRecipientPdf = fillInTemplate(map, recipientDonorPdfTemplate) />
<cfset filledDonorPdf = fillInTemplate(map, donorPdfTemplate) />
<!--- End of filled variables--->
<!--- Out put final string values - insert these into desired area for output.--->
<cfoutput>#filledEmail#</cfoutput>
<cfoutput>#filledRecipientPdf#</cfoutput>
<cfoutput>#filledDonorPdf#</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment