Web Crossing


Introduction

Installation & Upgrade

Web Crossing Features

Customizing & Scripting

UniqueIDs, Full Paths & URL Codes

Basic Customization

Server-Side Scripting

Web Crossing Template Language (WCTL)

WCTL Code Examples

Server-Side Scripting: Web Crossing JavaScript (WCJS)

User & Access Issues

Data Organization & Management

Performance Issues

Appendix

Site Map

WCTL Server-side Scripting
More WCTL

Introduction
Visitor Counter
Troubleshooting
Resources
Next Section

Introduction

In the previous section, you learned the difference between different variable types and experimented with user and author variables. In this section we will expand your use of WCTL by making a more useful, yet still very simple script - a visitor counter.

You will see how it is often easier to use WCTL to create your own customized features, rather than working with external scripting languages, such as Perl or other scripting languages.

A Visitor Counter

It is simplicity itself to add a visitor counter to your Web Crossing conference using WCTL.

In your Control Panel, edit the site banner (shown at the top of all pages, by default) and add the following line to your current banner:

%% set site.VisitorCount site.VisitorCount + 1 %%
This simple example uses the WCTL set command to increment (add 1 to) a site variable called VisitorCount. Let's examine the syntax in more detail to see how it works:
  • site.VisitorCount is a site variable. As we learned in the previous section, this means that VisitorCount is a global variable, stored in the Web Crossing database and available for use anywhere. If site.VisitorCount doesn't already exist, the above WCTL will create the variable upon execution and store a null value in it.

Note: Unlike some programming languages like C, WCTL is not a "typed" language. Basically all variables are considered to be character strings, which may be evaluated as numbers as needed. In this example, the initial value of site.VisitorCount is a null or empty string. When used as a number, the initial value is zero.


  • The set command is used to store a value into a variable. We have already seen values and variables, but let's just go over what they are one more time so we are clear on it. A variable is just the name of a place-holder that you can use to store things in, like names or numbers. An example of a variable is user.userName. A value is the actual contents held in a variable. An example of the value of a variable is the character string Doug. The set command can be used to store a value into a variable for later use.

  • The format of the set command looks like:

    %% set variable value %%


    The value is stored in variable. In our example variable is site.VisitorCount and value is the WCTL expression site.VisitorCount + 1.

    If the value of site.VisitorCount is 0, then the value of site.VisitorCount + 1 is 1. If the value of site.VisitorCount is 1, then the value of site.VisitorCount + 1 is 2. This expression increments the value of site.VisitorCount .

  • The incremented value is stored in the variable site.VisitorCount, which is saved automatically in the Web Crossing database and can be used later on.

Now that this is saved as part of your Web Crossing site banner, every time a conference page is opened that line of WCTL is silently executed. You won't see anything happen, because all you did was increment the value of site.VisitorCount. You have not actually used the value in a displayed page anywhere yet. However, the value will now be incremented by any user who opens any location in your conference which uses the default site banner.

Note: In this example, the site banner is used to increment the visitor counter. If you have separate banners set in your sub-folders, then the WCTL will not be executed at those locations because the local banner overrides the site banner. You can include the same WCTL in your local folder banner if you want to increment site.VisitorCount there as well.



To see the current visitor count, you now need to use the WCTL expression %% site.VisitorCount %% somewhere, just like you used %% user.userName %% in previous sections.

You can do this in the site banner, in your top level header, your user greeting, in a folder or any place you like.

For now, just go back and edit the site banner again and add the line

You are visitor %% site.VisitorCount %%

Now if you look at any page that displays the site banner you will see the current visitor count.

That is all there is to it! With just two lines of WCTL you created a site Visitor Counter and displayed it in your site banner.

There are additional commands for formatting the count number (such as adding commas automatically), but this is the general idea.

Next Section

In the next section we will look at WCTL conditional logic, which will give you even more control over the actions taken by your conference in controlling what users can see and do.

Troubleshooting

I tried the example above, but when I look at the header all I see is the WCTL itself, with all the double-percent marks. What am I doing wrong?

  • Make sure you have turned on WCTL evaluation in the Control Panels > General Settings:

Resources

Web Crossing FAQ:


Sysop docs:


WCTL Concept Reference Page

Web Crossing Tech Support Forum

Developer Center

WebX Harbor


A Non-Programmer's Guide to Web Crossing
by Sue Boettcher and Doug Lerner

© 2000 Web Crossing, Inc.