Importing other Aptilis scripts

Advanced topics

1. Introduction
2. How to use imports
3. Import conventions
4. Examples

1. Introduction

Imports allow you to re-use code and to keep your scripts concise.
The binary distributions of Aptilis do already include a small library of scripts, which you can use in your programs.
Aptilis has adopted the main characteristics of the package model from Java to avoid collisions between the scripts of different people. See Import conventions.

2. How to use imports

3. Import conventions:

Conventions are necessary to ensure that your own "library" doesn't come into conflict with the one of someone else.

4. Examples

These examples use the standard Aptilis library.

Example 1:

import apt.template.Html as Html

sub main()

    doctype = Html.Get("doctype_4_01_strict") $

    title   = "Welcome to my Homepage" $
    body    = "<h1>Hi there!</h1>" $
    head    = "<meta name=\"author\" content=\"John Doe\">" $

    print("Content type: text/html\n\n")


end main

Content type: text/html

        <title>Welcome to my Homepage</title>
<meta name="author" content="John Doe">
<body >
<h1>Hi there!</h1>

Example 2:

import apt.http.Cookie

sub main()

    cookiedata["ip"] = _ENV["REMOTE_ADDR"] $
    cookiedata["browser"] = _ENV["HTTP_USER_AGENT"] $


    print("Content-type: text/plain\n\n")

    oldcookie[] = apt.http.Cookie.Get()

    if cookiedata["browser"] != oldcookie["browser"] $
        print("Hey! You changed your browser!")
    end if

end main