Using Dreamweaver MX Snippets

Snippets are a new tool that allow you to collect and manage sections of Code. In many ways the Snippets Library is a code library.

In this article you will learn how to use Snippets in Dreamweaver MX and how to create your own Snippets.

 

Extending your Snippet collection beyond HTML

The main focus for this article has been with JavaScript. This is largely because the focus for Dreamweaver is on developing web pages. JavaScript is among the more complex elements used within a page design. Snippets, however, can manage any type of Script.

Dreamweaver now supports a large collection of server scripting languages such as C#, PHP and Java. Each of these can have their own collections in the Snippets Panel.

Within the Snippets Panel right click on the top category and select New Folder. This allows you to create a new folder in which you can add additional Snippets.

Create a new folder and name it PHP. Create a new Snippet and name is "Days of the Week." Add the following block of code:

function is_leap_year($year) {
if ((($year % 4) == 0 and ($year % 100)!=0) or ($year % 400)==0) {
return 1;
} else {
return 0;
}
}

function iso_week_days($yday, $wday) {
return $yday - (($yday - $wday + 382) % 7) + 3;
}

function get_week_number($timestamp) {
$d = getDate($timestamp);
$days = iso_week_days($d["yday"], $d["wday"]);
if ($days < 0) {
$d["yday"] += 365 + is_leap_year(--$d["year"]);
$days = iso_week_days($d["yday"], $d["wday"]);
} else {
$d["yday"] -= 365 + is_leap_year($d["year"]);
$d2 = iso_week_days($d["yday"], $d["wday"]);
if (0 <= $d2) {
/* $d["year"]++; */
$days = $d2;
}
}

return (int)($days / 7) + 1;
}

Here is a simple PHP snippet. Working with a client that needs PHP, now you have a way to calculate days of the week.

Now,  you can add a second folder named C#. Here is the code you will need to create days of the week quivalent in C#:

<%@ Page LANGUAGE="CS" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM runat="server">

<H3>Calendar Example</H3>
<asp:Calendar ID="calendar1" runat="server"
ShowDayHeader="True"
DayNameFormat="Full"/>
</FORM>
</BODY>
</HTML>

Now you have two different languages that deliver the same result saved as Snippets. 

Matthew David

Matthew David has been developing Flash based applications for over 6 years (that makes him very old in this business!). Examples of his work can be found at his web site www.matthewdavid.ws, or you can email him directly at mdavid@email.com.

Matthew’s most recent publications include content for Flash 5 Magic, Inside Dreamweaver 4, Flash 5: Visual FX, Web Publishing Bible and The Dreamweaver Bible. You can also see him popping up in many online magazines, such as Sitepoint.com, Windowatch.com, UDzone.com and DevX.com.

Currently, Matthew is working on two books and writing articles for Element K Journal’s Macromedia Solutions magazine. He is a available as a freelance consultant to work on web based projects.

See All Postings From Matthew David >>

Comments

Be the first to write a comment

You must me logged in to write a comment.