The amazing adventures of Doug Hughes

From time to time I’ve wanted to be able to parse Dreamweaver template files from ColdFusion. I wrote a solution a year ago which did a fine job. But, I worked on it a bit more today and came out with two CFCs which work rather well.

These CFCs only support the standard Dreamweaver template editable regions. At some point in the future I may add support for optional and repeating regions. I wanted to do a full implementation, but template expressions proved to be too much of a pain to bother with at the moment.

With without further ado, you can download the Dreamweaver CFCs below. The zip file contains two CFCs, template.cfc and instance.cfc. The template.cfc is used with a Dreamweaver template file (a DWT). The instance.cfc is used with a document created from a Dreamweaver template.

Template.cfc

The template.cfc is used to read and work with a Dreamweaver template file (DWT) and provides these methods:

readTemplateFromFile(file)

The readTemplateFromFile method is used to read a DWT file. The file argument specifies the path to the DWT file being read.

writeTemplateToFile(file)

The writeTemplateToFile method is used to write the DWT back to disk. This is of use in the case that you use setRegionDefaultValue method to change the template’s region’s default values.

getRegionNames()

The getRegionNames method returns an array of all the region names in the template. This can be used in conjunciton with the setRegionDefaultValue method to set default values for regions.

getRegions()

The getRegions method returns an array of structures describing all of the template’s regions. The each array element corrisponds to an editible region within the template. Each array element is a structure containing the following items:

Name – The name element is the name of the editible region. This can be used with the get/setRegionDefaultValue method to get or set the region’s default value.

Content –
The content element is the entire contents of the template editable region including the Dreamweaver template markup.

DefaultValue –
This is the default value for the editible region.

Start –
The start element is the index of the first character of the Dreamweaver editible region HTML template markup.

End –
The end element is the index of the last character of the Dreamweaver editible region HTML template markup.

setRegionDefaultValue(region, value)

The setRegionDefaultValue method is used to set a region’s default value. The region argument is the name of the region to change. This can be obtained using the getRegionNames method. The value is the value to set as the default for the region.

getRegionDefaultValue(region)

The getRegionDefaultValue method can be used to get a region’s value. The region argument is the name of the region to get the value of.

createInstance(rootRelativePath)

The createInstance method creates a new Instance object based upon the Template. The rootRelativePath argument indicates the path to the DWT file from your website’s root directory.

setTemplate(template)

The setTemplate method is used to set the template html. The template argument is the contents of the DWT file.

getTemplate()

The getTemplate method returns the HTML of the Dreamweaver template.

Instance.cfc

The instance.cfc is used to read and work with a files based on Dreamweaver template files and provides these methods:

readInstanceFromFile(file)

The readInstanceFromFile method reads a document based on a Dreamweaver template from a file. The file argument specifies the path to the file to read.

writeInstanceToFile(file)

The writeInstanceToFile method is used to write the an instance back to disk.

getRegionNames()

The getRegionNames method returns an array of all the region names in the instance. This can be used in conjunciton with the setRegionValue method to set values for regions.

getRegions()

The getRegions method returns an array of structures describing all of the instance’s regions. The each array element corrisponds to an editible region within the instance. Each array element is a structure containing the following items:

Name – The name element is the name of the editible region. This can be used with the get/setRegionValue method to get or set the region’s value.

Content – The content element is the entire contents of the instance editable region including the Dreamweaver template markup.

Value – This is the default value of the editible region.

Start – The start element is the index of the first character of the Dreamweaver editible region HTML template markup.

End – The end element is the index of the last character of the Dreamweaver editible region HTML template markup.

setRegionValue(region, value)

The setRegionValue method is used to set a region’s value. The region argument is the name of the region to change. This can be obtained using the getRegionNames method. The value is the value to set as the default for the region.

getRegionValue(region)

The getRegionValue method can be used to get a region’s value. The region argument is the name of the region to get the value of.

setInstance(instance)

The setInstance method is used to set the instance’s html. The template argument is the contents of the instance file.

getInstance()

The getInstance method returns the HTML of the template instance.

Comments on: "Dreamweaver Template CFCs" (5)

  1. Hi Doug!

    this component is excactly what I need. But how do I use it? I’m new to cfc’s… so, could you give a short code sample?

    Like

  2. I realize this is old, but there are no longer any zip files connected to this post. I’ve been toying with this concept recently; any chance of getting ahold of these CFCs?

    Like

  3. Doug Hughes said:

    @Mark – It took some digging but I found the zip. It’s now attached to this blog entry.

    Like

  4. Excellent. Thanks!

    Like

  5. Since we are discussing Dreamweaver Template CFCs – Alagad Ally, CSS templates provide you with an easy way of stylizing your web pages allowing you to work with content and style separately. They will become a great basis for a business website you want to set up due to many advantages they possess. Attractive design, great functionality and ease at use and customization make the CSS templates a perfects choice for business website creation.

    Like

Comments are closed.

Tag Cloud