Ask a Jedi: onMissingTemplate in ColdFusion 7?

Craig asks:

Do you know how to handle MissingTemplate errors on the application level in CF7. I know CF8 has a new application function onMissingTemplate() that handles this but am having difficulties with this in CF7.

So Craig is right - this support is something that was added to ColdFusion 8, not 7. You can certainly add it to your Application.cfc but it won’t fire automatically. (Folks, don’t forget that Application.cfc can include additional methods!)

In ColdFusion 7, the only option you have similar is the Missing Template handler in the ColdFusion Administrator:

This is server wide, and unlike onMissingTemplate, you can’t do processing before the file itself is loaded. So for example, if you want to say that any missing template with “store” in the URL should point to store.foo.com, you would need to put that logic within your CFM.

You do have access to the requested template information - but not via an explicit passed in arguments but rather the CGI scope instead.

So - it isn’t quite as nice as onMissingTemplate, but it’s something. I’m convinced that simply ignoring 404 requests is one of the biggest mistakes you can make on a web site (and I admit to this as well!).

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments