heitml takes the
World Wide Web
to a higher level!

Introduction
heitml Features
       

Language Guide

   Web Page Templates
   Creating SQL Tables
   Creating FORMs
   Database Access
   Altering SQL Tables
   Updating SQL Tables
   A Sample Program
   User-defined Functions
   Control Statements
   dba Tutorial
   Session Mode
       
Language Reference
The heitml Libraries
Supported Platforms
User Guide
Download
User Registration
Discussion Group
Mailinglist
       
NEW!
heitml 1.2 new features


Send us mail

Contact Info

   

heitml Language Guide
by Keith Oustalet

Control Statements
heitml provides two basic control Tags called <if> and <while> which, as we will see shortly, can be used in a wide variety of situations. Although heitml is not normally a Case Sensitive language, internal Tag names such as "if" and "while" must always appear in lower case, otherwise heitml will not recognize them. Needless to say, this will cause your programs to react in a manner different from what you intended.

Earlier in the Language Guide we mentioned the fact that, in additon to standard HTML syntax, heitml Tags can use an alternate syntax to eliminate some of the clutter caused by all the "< >" symbols that appear in HTML pages. Although we will introduce the <if> and <while> Tags using the traditional HTML syntax, from now on, when appropriate, we will use the alternate syntax to give our Source Code examples a cleaner look. (For a more complete discussion of heitml's alternate syntax, see "heitml as an integrated Template and Programming Language" in the General Design page of the Language Reference.)

Here is the <if> Tag in its basic form:

<if condition> Do This <else> Do That </if>

And here is a similar example for the <while> Tag:

<while condition>
      Other heitml & HTML Tags and Text
</while>

These two examples, while deceptively simple, lay the foundation for the development of incredibly flexible and sophisticated Web Applications. Let's see if we can describe a few situations that demonstrate what we are talking about.

At the time this is being written, anyone with Internet access can visit the Web Sites of Microsoft or Netscape to download a free copy of the most current version of their Web Browser software. One would think that such a policy would almost guarantee that everyone in the Web Community would always use the latest Browsers these companies have to offer. In truth, however, there are many reasons why we find a lot of people using old Browers that do not support the latest features.

In any event, Web Designers often find themselves in a position where they either have to choose between creating simple, "plain Vanilla" Web Sites catering to the least capable Web Browsers, or they are forced to maintain multiple versions of their Web Sites. This stiuation could be as simple as the old "Frames/no-Frames" issue, but today it more often involves issues related to competing technologies like JavaScript, VBScript, JavaApplets, and ActiveX, not to mention the ever growing number of Plugins available from other Vendors.

Fortunately, heitml offers a way to find out what kind of Web Browser and Operating Systsm is being used by the people who Surf your Site and, in combination with the <if> statement, set up multiple pathways to service these Users from within a single Web Page.

One of the Built-in Server Variables heitml recognizes is called SrvUserAgent. (See Server Information in the heitml Running Examples section for a complete list.)

Here is the information SrvUserAgent shows us about you:

MSIE

And here are some of the things we've seen returned by the SrvUserAgent variable about other people surfing our Web Site:

Mozilla/3.01 (Win16;I)

Mozilla/3.01 (Win95;I) via proxy gateway CERN-HTTP/3.0 libwww/2.17

Mozilla/2.0 (compatible;MSIE 3.0b; Windows 3.1)

Mozilla/2.0 (compatible;MSIE 3.0B; Win32)

Mozilla/2.0 (X11; I; SunOS 4.1.3_U1 sun4m)

If this seems like a confusing variety of information to get from a single variable, don't worry. The important thing here is that in all cases the SrvUserAgent tells us which Browser and Operating System a person is using.

In order to make this clear, heitml has a tool we can use that checks to see if a specific string of characters is contained within a Variable. For instance, we could use the SrvUserAgent as the string to be searched, and call the contains( ) Function as an expression to be evaluated by the <if> Tag.

Here's an example of how that might work:

 <if contains(SrvUserAgent,"MSIE 3") 
 && contains(SrvUserAgent,"Win32")
  > Your Browser supports ActiveX and VBScript < 
 else
  if contains(SrvUserAgent, "MSIE 3")
  && contains(SrvUserAgent, "Windows 3.1")
   > ActiveX is not supported on Windows 3.1 <
  else
   if contains(SrvUserAgent, "Win16")
   || contains(SrvUserAgent, "Windows 3")
    > Java Applets not supported on this OpSys < 
  /if
 /if
/if>

In the above example the two &&-symbols represent a logical AND condition. In other words, only "if This AND That" are true, will the condition be satisied. The two ||-symbols represent an OR condition, which means a condition is satisfied "if This OR That" is found to be true.

Also, we have surrounded the text statements outputted by each condition in wing-like brackets "> <" to help clarify the fact that one of the features of the heitml alternate syntax is that all text and old-style HTML Tags are executed from "within the wings" so to speak. We'll see more about this alternate syntax in our next example.

For instance, our first example above is provided merely to show how you would build <if> statements that test multiple conditions. In a real-world application you wouldn't just print a message telling a User what features his Browser does or does not support. Chances are he already knows some of the strengths and weaknesses of his given Browser and, for reasons of his own, has decided to stick with it.

Instead, the <if> Tag, contains( ) Function, and SrvUserAgent variable should be used with the thought in mind of discovering things about your Users that later help you dynamically assemble and ship versions of your Web Pages that best take advantage of the capabilities of each User's Browser.

Imagine, for example, that you want to design a re-useable code module to be placed at the top of every Web Page you develop. This code module would be designed to interrogate the SrvUserAgent variable and set values to Global Variables. These values would then tell your application what features should or should not be included in a Web Page. In effect, they would serve as "Guides", creating different views of your Web Pages to different Users.

Here's one way you might do this:

 
/ / User-defined Tags go first.
<def SetUserBrowserValues;

  / / Initialize Global Variables to "false"
  gl.ActiveX    = "false";
  gl.VBScript   = "false";
  gl.JavaApps   = "false";
  gl.JavaScript = "false";

  / / Test for Browser & OpSys.
  if contains(SrvUserAgent,"MSIE 3") 
  && contains(SrvUserAgent,"Win32");
     gl.ActiveX    = "true";
     gl.VBScript   = "true";
     gl.JavaApps   = "true";
     gl.JavaScript = "true";
  else
   if contains(SrvUserAgent, "MSIE 3")
   && contains(SrvUserAgent, "Windows 3.1"); 
      gl.VBScript   = "true";
      gl.JavaScript = "true";
   else
    if contains(SrvUserAgent, "Mozilla/3")
    && contains(SrvUserAgent, "Win95");
       gl.JavaApps   = "true";
       gl.JavaScript = "true";
    else
     if contains(SrvUserAgent, "Mozilla/2")
     && contains(SrvUserAgent, "Win32");
        gl.JavaApps   = "true";
        gl.JavaScript = "true";
        gl.VBScript   = "true";
     else
      if contains(SrvUserAgent, "Nozilla/2") 
         gl.JavaScript = "true";
     /if
    /if
   /if
  /if
 /if;
/def>

/ / Program execution begins here.
<SetUserBrowserValues;
 ShowLogo;
 ShowSlogan;
 ShowIntroText;

 if gl.ActiveX = "true"; LaunchActiveXmenu; 
 else 
  if gl.JavaApps = "true"; LaunchJavaAppMenu; 
  else ShowHTMLmenu;
 /if
/if;

 MoreStuffGoesHere;
 ShowNavigationToolBar;
 ShowEmailInfo;
 ShowCopyrightMessage
> 

Notice in the above example that we first set all Global Variables to false as a Safety Valve. This assures that no Browser Specific features will be launched unless it has been determined that it is safe to do so.

Notice also, that instead of constantly opening and closing our heitml Tags with "< >" symbols, we simply separated them with a semi-colon. As you can see, the heitml alternate syntax is closer to what you would expect to find in a programming language because, in fact, heitml is a full-featured programming language. We think you'll find that, as your Web Pages become more heavily populated by heitml Tags and control statements, you will come to depend on this syntax, simply because it makes your code easier to read and understand.

You don't have to use this "programming" syntax if you don't want to, but it provides an easy method of separating heitml Tags from standard HTML Tags, thus helping you to keep track of when you are in "programming mode" and when you're in old-fashioned "text mode" (i.e. HTML mode).

One final thing to notice about the above example is that you no longer see any HTML Tags. HTML is a Document Discription Language. heitml is a modular Programming Language. The more highly structured and modular your code is, the more insulated you are from the underlying HTML formatting details. HTML Tags are still very much a part of heitml programming, but they don't need to clutter up your code, making it difficult to read. If you want to make changes to the <ShowIntroText> or <ShowNavigationToolBar> modules, your merely have to go to the section of code where those modules were defined. Otherwise, they stay out of your way, allowing you to examine the flow of your application from the perspective of a high-level overview.


Before leaving this page we'll give a short example of how to use the <while> Tag. The <while> Tag is designed for situations where a procedure will be executed one or many times, depending on a certain condition. For instance, in database applications it is common for a search query to return more results than can reasonably be listed on a single Web Page.

Here's a technique using the <while> Tag that limits the number of records displayed resulting from an SQL Search Query:

 
<dbquery
   > SELECT * FROM guestbook < 
   dbhead; fname; 
   dbbody; i = 0;
   while i < 10;  
     dbrowbegin; 
       dbcolumn; field; 
     dbrowend; i = i + 1;
   /while; 
/dbquery
>

Even though the above SQL SELECT statement uses the asterisk to indicate that it wants the query to return every record from the Guestbook table, the while i < 10; limits the amount of data that is outputted to the Web Page.


This page was dynamically generated by heitml
© 1996-1997 H.E.I. All Rights Reserved

heitml documentation (c) 1997 H.E.I. GmbH Mannheim, Germany