Creating Custom Variables
Introduction
Creating Custom Variables
Custom Path Variables
Creating Custom User/Author Variables
Troubleshooting
Resources
In the previous section, we talked about how to edit entire macros. This allows you to customize nearly the entire user interface! And you can even add features that don't normally come with Web Crossing.
One thing that's very handy to know, and which helps you add features, is how to create your own custom user and path variables.
It's pretty easy, and very useful. You already saw how to add a site variable in the lesson where you created a visitor counter. Adding user and path variables isn't much harder.
Custom variables are named very much like built-in variables. The built-in variable %% user.userName %% keeps track of the user's user Name. Using the same strategy, we could refer to a custom user variable to display your members' ICQ numbers as %% user.icq %%
All you have to do to use a custom variable is to give it a value, and Web Crossing will store it so you can display it next time you ask for it.
You can give it a value using the set command:
%% set user.icq 43533401 %%
or you can send it in a field in a form that's submitted:
<input type="text" value="%% user.icq %%" name="user.icq">
Note: Including the value="%% user.icq %%" as part of the HTML tag ensures that when the user comes back to edit the page on which this field is displayed, the existing value will be filled into the blank already. |
Setting a Custom Path Variable in a Folder Heading
To illustrate how path variables work, we'll create two test discussions.
Create one discussion and call it Test 1. Create a second, and call it Test 2.
In the heading of the Test 1 folder, type this:
%% set path.note "This is a special note about the Test 1 Discussion." %%
%% path.note %%
This code simply sets the value of path.note to the sentence in quotation marks, and then displays the contents of %% path.note %%.
After you make the edit and click OK, the Test 1 Discussion description should read:
This is a special note about the Test 1 Discussion.
Now edit the discussion description again, and remove the whole line that begins with "set path.note...," including the percent signs, so that all that's left is %% path.note %%.
After you click OK, the description still reads:
This is a special note about the Test 1 Discussion.
Were you surprised the text is still displayed, even through we removed the "set" command line? We haven't told the value of the variable to change, so it stays the same. It was set the first time we edited the description, and we didn't change it this time. It will stay the same every time this discussion is viewed, unless we tell Web Crossing otherwise at some point.
Now go to Test 2 and edit the description. Type in:
%% path.note %%
Take a look at what is displayed in the description now. Nothing! We defined path.note for the Test 1 discussion, but not for the Test 2 discussion. If we wanted to, we could use a similar "set..." command to set an entirely different value (sentence) for path.note for this discussion. But until we do, the value of path.note for this discussion is empty, or "null," and thus nothing is displayed.
Setting Custom User/Author Variables
Setting custom user variables is just as simple. The most useful way to set a custom user variable is in a form field either in the registration form macro (Registration macro) or on the page to edit preferences (edit Preferences macro).
Some examples of things you might want to include are: the ICQ number we mentioned earlier, an AOL Instant Messenger username, a state or country, or a business affiliation. Or anything else you can think of a use for.
The basic process is to include a form field similar to this:
<input type="text" value="%%
user.icq %%" name="user.icq">
in the Registration or Preferences form.
Then you can display the value of %% user.icq %% wherever you want. You will probably want to put it on the Edited Preferences macro page (the page that comes up after you change your preferences), and on the author information page (which comes up when you click on an author's name).
But remember: if you include it on the author information page, you'll have to display it as:
%% author.icq %%
since it is the post author's information you want to see, not that of the user viewing the discussion! For a review of author vs. user variables, see the section on distinguishing them.
The next section will show you how to intercept and filter processing of login requests, registration requests, preferences changes, and more.
I tried the example above, but when I look at the description all I see is the WCTL itself, with all the double-percent marks. What am I doing wrong?
Web Crossing FAQ:
Sysop docs: