![]() |
Templates TutorialIn order to ease the development of common interface constructs like windows, buttons, scrollbars and menus, a number of templates are available as standard when DML is installed on a user's system. The availability of these templates means that you are relieved of the task of creating common controls yourself. Template files are stored in the "templates:" directory of your installation, so you can check this directory to see what's available on your own system. Each template has its own set of documentation, so if you open the DML files in a text editor, you can read up on how each template works. Why Templates Make Life EasierEarlier in our tutorials we showed you how to create a fully functional, interactive button. In reality however, the last thing you want to do is copy and paste the same large amount of code every time you want to create a button within an application. As luck would have it, a template to create buttons already exists. Here's a button that's based on the template: This is the code that we used to create it: <button x="0" y="0" xoffset="0" yoffset="0" text="Click Me!"/> Wow, only one line - and to think we went through all that effort earlier when a single line would have sufficed! This makes our point on the power of using templates to the fullest - they can save you a lot of time and effort. Here's a table that lists the most commonly used templates and what they are for:
Calling TemplatesCalling a template is extremely simple, as the DML interpreter allows you to call them as if they are standard object-based tags. For instance, to create a new window you would use a tag similar to the following:
<window x="10" y="30" insidewidth="200" insideheight="200">
dml content
</window>
It is also possible to call templates with the script tag, for example:
<script src="templates:window" x="10" y="30" insidewidth="200" insideheight="200">
dml content
</script>
When using the window template with the DML Internet plugin, it is important to note that unless you have opened a DML desktop within the embedded area, the plugin will open a standard window that is independent of the user's Internet browser and the HTML page. In such a case, you should keep in mind that the window will automatically close when the user leaves the HTML page from which the window was created. Customising TemplatesOne of the most useful aspects of templates is that the location of the template files can be redirected to other directories. What this essentially means is that the user can adjust the look and feel of your application by creating new template files and redirecting all DML scripts towards them. This allows the look and feel to be easily adjusted without having any adverse effects on your application. In some cases your application may take on a very different appearance to your original intentions, but the end user will be happier with a program that is tuned to their own environment, while still behaving the way you intended. To customise your templates, you can either edit the files directly (this is not recommended) or you can copy the contents of the "templates:" directory to a new location and refer to it in your "user:config/asssignments.cfg" file by adding the suggested template line: [LIST] ... templates = path:your/template/directory/ Once you restart the system, the templates will be loaded from the location that you have set. Copyright Rocklyte Ltd © 2002-2007. |