DML2  v1.0.1
Sections
Introduction to DML2
Getting Started
Files and Directories
Custom Tags
File Output
Creating Objects
Rendering and Scope
Object Execution
Arrays
Rendering Arrays
Constructors
Includes
Automatic Tags
dml2build
About
Release Notes
<( Creating Objects )>

Now that you know how to make custom tags and output files, you're up to the level of the classic DML masters; this is all the functionality that DML has. With what you've learned, you could write pages more quickly and then change the design (slightly) without having to edit every HTML file by hand. But what if you want to move your side bar to the bottom of the page? Or, in a clever attempt at an April Fool's Day joke, you want to output your site into ASCII text? This is where DML limits you. Fortunately, DML2 builds on these ideas and allows you output your content into any format you choose, each format with their own unique structure and layout.

DML2 objects are what you should use to store your site/document's content. If you store all of your content within these objects, your entire site can be rebuilt by simply changing around a template file. (When I say template file, I really mean a DML2 file that has render/tag definitions for a particular format.)

An object can hold properties (using the val keyword) as well as other objects and arrays of objects/properties. An object is declared by typing object followed by white space (spaces/tabs) and then the object type's name. Finish the line off with an opening brace ({). Between a line that contains only a closing brace (}) and the first line are the members of the object. A member is declared by inserting the member's type followed by an identifier (name). Members are what store the data inside of a DML2 object. If you're feeling lost, an example should explain all of this.


object Date {
      val month
      val day
      val year
      Time timestamp
}


Since objects are the most difficult to understand (and most powerful) aspect of DML2, I'll go through this example line by line. The first line starts the definition of the Date object type. The second line defines a property called month. A property is the simplest type in DML2; it just holds a block of text (that may include DML2 tags). Lines 3 and 4 are similar to line 2 only with different names. Line 5 declares a member of type Time. This type (Time) is a type that has been previously declared somewhere in the same file or an included file (there will be more on files later). The last line, of course, concludes the declaration.


!Note: You'll notice that I have indented the definition of members in an object. This is C-style syntax and is completely optional (but highly recommended!)


Ok, so we've got an object type defined. By itself, this does nothing. Date is just a generic type that states what an object of that type will contain. To get an actual object of that type, you must instantiate (that is, make an instance of) Date. Here's how this is done:


Date someDate


Wow, that was rough. Hopefully you're still with me ;). Now that we've got an object of type Date, we can start assigning values to it. To access the members inside of an object, just type the parent object's name, a period (.) and then the member's name. Note that this is a recursive process, so object.aMember.aMembersMember will traverse down the tree of objects until it finds the object you're looking for. To assign a value to a property, just type the name of the property followed by white space, an equals sign, more white space, and then the new value surrounded by quotation marks. (Note, the rule about using \" applies here as well)


someDate.month = "January"
someDate.day = "6"
someDate.year = "2002"


You can also assign an entire object to the values of another objects of the same type. Here's how this could work:


Date anotherDate
anotherDate = someDate


In this example, anotherDate now has all of its members' values set to the same things as someDate.


!Note: When you assign an object to another object of that same type, all of its members are copied into the new objects; they are in no way linked. This means if you make a change to an object after it is copied, the original object will be unaffected.


In case you haven't noticed, all of your content will eventually end up inside of DML2 properties. Objects are just useful aggregations of data that is stored in properties. To reinforce this point, the "type" of a property is val.

http://derajdezine.vze.com/
©2002 Jared Krinke. ((( Revolution )))