Skip to content

Instantly share code, notes, and snippets.

@SirRawlins
Last active December 11, 2015 21:39
Show Gist options
  • Save SirRawlins/4664075 to your computer and use it in GitHub Desktop.
Save SirRawlins/4664075 to your computer and use it in GitHub Desktop.
This is a short process which collectes the directory path of a CFC, and uses it's location to find a related view by convention. For instance, if the CFC path is /mailers/foo/bar.cfc the view location would be /views/email/foo/bar/ This is done simply at the moment by using REGEX to switch the '/mailers/ directory with '/views/email' in the CFC…
<!---
No path for the view was set into the payload so we
render a view based on the conventions.
--->
<!--- Get the full directory path of this mailer object. --->
<cfset LOCAL.MailPath = getDirectoryFromPath(getMetaData(this).path) />
<!--- This path MAY be a windows path, with backslashes so I'm going to normalize this into a NIX path. --->
<cfset LOCAL.MailPath = Replace(LOCAL.MailPath, '\', '/', "ALL") />
<!--- Append another direct for the file name of the mailer. --->
<cfset LOCAL.MailPath &= ListLast(getMetaData(this).name, '.') />
<!--- Now we have a potential location, we need to replace /mailers with /views/email so the correct path is found. --->
<cfset LOCAL.MailPath = Replace(LOCAL.MailPath, '/mailers', '/views/email', 'all') />
<!--- Now we can guess the expected files for HTML and Text based layouts. --->
<cfset LOCAL.HTMLTemplate = LOCAL.MailPath & '/' & ARGUMENTS.MethodName & '.html.cfm' />
@SirRawlins
Copy link
Author

I managed to solve the issue related to the NIX/Windows file paths. I did this by normalising the path replacing all \ with / before any of my regex to replace things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment