Builder Extension using HTML

One of the cooler features of ColdFusion Builder’s extension tooling is the ability to create extensions that are driven with HTML/JS/CSS instead of with the default XML options. I think this has a few advantages:

  • Allows interface options enabled by the XML options
  • Allows better branded extensions via CSS and background images
  • Allows you to develop/debug your extensions like normal web applications

This is pretty easy to enable. Normally you would have code like this in your handler to communicate back to the IDE:

<cfheader name="Content-Type" value="text/xml">
<response status="success" showresponse="true">
    <ide >
        <dialog width="600" height="400" />
                Some Response

Instead you pass a URL parameter to the ide tag in your extension handler:

<cfheader name="Content-Type" value="text/xml">
<response showresponse="true">
    <ide url="http://localhost/extension/handler.cfm?configPath=#configPath#" >
        <dialog width="655" height="600" />

As you can see it can even handle URL variables.

Now, where I ran into trouble with this was with the URL itself. Basically you can’t be sure of the URL when dealing with extensions. It could be localhost, but it just as easily could be on a remote server. So I was all clever and wrote some code to handle this:

<cfset baseURL = "http://" & cgi.server_name  />
<cfset messagesPath = getDirectoryFromPath(cgi.script_name) & "/messages.cfm" />
<cfset messagesOptions = "?type=notanapplication" />
<cfset messagesURL = baseURL  & messagesPath & messagesOptions >


You see, this will give me the correct URL to use to pass information to a template named “messages.cfm” that sits in the same folder as my handler. I use CGI variables to grab the server information. Then I use getDirectoryFromPath to make sure that I get the real relative path of the folder that the extension is sitting in (as opposed to assuming that it lives in the webroot). This works great.

Except I got reports of one of my extensions not working at all for some people. Look at that code again… There’s another big assumption there. The assumption is that the extension is being called over the default http port, which for many ColdFusion developers it isn’t. So the correct version of this code goes:

<cfset baseURL = "http://" & cgi.server_name & ":" & cgi.server_port />
<cfset messagesPath = getDirectoryFromPath(cgi.script_name) & "/messages.cfm" />
<cfset messagesOptions = "?type=notanapplication" />
<cfset messagesURL = baseURL  & messagesPath & messagesOptions >

Doing this you can be sure that you hit the right URL regardless of:

  • Server hostname
  • Server http port
  • Relative location of extension to the webroot

Happy extension building.

One thought on “Builder Extension using HTML

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s