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:

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.

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?

Resources

Web Crossing FAQ:

Sysop docs:

WCTL Concept Reference Page

Web Crossing Tech Support Forum

Developer Center

WebX Harbor