Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite 6
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions
  • Government

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / Dreamweaver Developer Center /

Creating user-defined functions for ColdFusion 8 in Dreamweaver CS4

by Raymond Camden

Raymond Camden
  • raymondcamden.com

Created

22 December 2008

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
client-serverColdFusion 8Dreamweaver CC CS4dynamic websiteextensibility
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Requirements

Prerequisite knowledge

Familiarity with Dreamweaver and ColdFusion.

User level

Intermediate

Required products

  • Dreamweaver CC (Download trial)
  • ColdFusion (Download trial)

Sample files

  • creating_udfs.zip (ZIP, 4K) (1 KB)

In this tutorial, you'll learn how to create a simple user-defined function (UDF) for ColdFusion 8 in Dreamweaver CS4 that will provide an easy way to format date and time data using one simple function. ColdFusion provides nice time and date formatting, but no way to format both a date and time together. The UDF will solve that problem.

You may wonder why building UDFs is useful at all. UDFs let you take a process, any process really, and collapse it into one simple call. A real-world comparison would be running to the store to get coffee. This process involves multiple steps: getting the car keys, driving to Starbucks, buying the coffee, and driving back home. If you needed to do this multiple times (and who doesn't drink more than one cup of coffee), you would have to repeat the steps multiple times as well. If you could gather these steps into one process, though, called "getCoffee," then you can simplify the process. If this were code, instead of having 5 to 6 lines of code every time you needed to get coffee, you would define the process once (in the UDF) and then simply run getCoffee() every time you needed it.

Setting up Dreamweaver CS4

In this section, you'll set up Dreamweaver CS4 and ColdFusion Server and the tags you'll need to create the UDF.

  1. Define a ColdFusion site in Dreamweaver CS4.

    Note: For more details on how to set up a site in Dreamweaver, see Setting up a Dreamweaver site in Dreamweaver Help or view the video Defining a site.

  2. Create a new CFML page and save it as test.cfm within /cf_webroot/dw_udfs/ (create the folder if it does not yet exist).
  3. In Dreamweaver, select the Insert > CFML > Advanced tab, and then the More Tags (the last option in the CFML Advanced tab) option.
  4. Expand the CFML Tags folder and select Extensibility (see Figure 1).
Selecting the cffunction
Figure 1. Selecting the cffunction
  1. Select cffunction from the list and click Insert. The Tag Editor dialogue box appears. Name the function formatDateTime (see Figure 2). Click OK and then Close.
Naming your cffunction tag.
Figure 2. Naming your cffunction tag.
  1. Change to Code View in Dreamweaver CS4 and locate the cffunction tag that Dreamweaver inserted into test.cfm.
  2. Place your cursor between the beginning and end tags for cffunction and press Enter twice to insert an extra space. Your code should look like the following:
<cffunction name="formatDateTime" output="no" verifyclient="no" securejson="false"> </cffunction>
  1. Put your cursor between the cffunction tag and press Enter so that you are on a new line. You will now repeat steps 3 through 6 for the cfargument tag. Complete the dialog box as shown in Figure 3 (name the cfargument tag datetime, selecting Date for Type, and select the Required check box). Be sure that you press Enter after the cfargument tag to begin a new line.
Naming the cfargument tag.
Figure 3. Naming the cfargument tag.

The argument will pass the datetime field (a date and time value) into the UDF from your page, and requires a value.

Next, you will create a variable. You will use the var keyword to tell ColdFusion that this variable is for this function only. It will be defined as a local variable and will be discarded when you execute the cffunction tag. You can leave your variable empty as it will be populated from the rest of the code in the UDF.

  1. Select cfsetfrom the Insert/CFML tag list. This inserts an empty cfset tag for you. Name the variable formattedString. Add var before formattedString and after cfset. Then add = "" to keep its value empty, as shown below:
<cfset var formattedString = "">
  1. As I mentioned at the beginning of this article, ColdFusion has functions to format dates and times. You will use both these functions together to create the result of the UDF. Press the Enter key to add a blank line after the previous cfset and paste in the following code:
<cfset formattedString = dateFormat(arguments.datetime) & " " & timeFormat(arguments.datetime)>

This sets the value of formattedString to the combination of two ColdFusion functions: dateFormat and timeFormat. Note that you also add an empty space between these two functions. Both dateFormat and timeFormat allow you to specify format options, but for now you are simply going to use the defaults.

  1. Now you need to return this value out of the UDF. Once again return to the CFML Advanced, Extensibility tag list, and this time select CFRETURN. This inserts a blank cfreturn tag. Inside the tag you need to specify the value to return. Enter formattedString. The following snippet shows the complete UDF:
<cffunction name="formatDateTime" output="no" verifyclient="no" securejson="false"> <cfargument name="datetime" type="date" required="yes"> <cfset var formattedString = ""> <cfset formattedString = dateFormat(arguments.datetime) & " " & timeFormat(arguments.datetime)> <cfreturn formattedString> </cffunction>

Testing the UDF

Now that you've written the UDF, it's time to begin playing with it. Place your cursor after the end of the function and press the Enter key a few times. To call the UDF you just created, you use the same syntax you would for any regular built-in user-defined function. For example:

<cfoutput> #formatDateTime(now())# </cfoutput>

This displays your current date and time (for example, 30-Oct-08 08:45 PM). You can also specify a date and time using the createDateTime function:

<cfoutput> Santa will pass #formatDateTime(createDateTime(2008, 12, 24, 23, 59, 59))# </cfoutput>

This displays: Santa will pass 24-Dec-08 11:59 PM.

Where to Go Next

This article only scratches the surface of what you can do with UDFs. For more information be sure to read the documentation included with ColdFusion 8. For a huge selection of UDFs to use with your own projects, visit the Common Function Library Project, which contains hundreds of ColdFusion UDFs—all free and ready for immediate download!

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Creating a Spry XML data set
  • Which server-side technology should I choose?
  • Exchanging data using the Spry framework for Ajax and PHP
  • Managing multiple subscriptions in PHP
  • Creating and consuming ColdFusion components and web services with Dreamweaver CS4
  • Creating custom server behaviors and Dreamweaver extensions
  • Building your first dynamic website – Part 1: Setting up the site and database
  • XSL overview
  • Creating master and detail ColdFusion pages
  • Creating a ColdFusion upload page in Dreamweaver CS4

Tutorials and samples

Tutorials

  • Creating your first website – Part 3
  • Creating your first website – Part 4
  • Creating your first website – Part 5
  • Creating your first website – Part 6

Samples

  • Responsive design with jQuery marquee
  • Customizable starter design for jQuery Mobile
  • Customizable starter design for HTML5 video
  • Customizable starter design for multiscreen development

Products

  • Adobe Creative Cloud
  • Creative Suite 6
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy (Updated) | Cookies

Ad Choices