Up and Running with Frontier Web Site Management
by Matt Neuburg
Author of the book Frontier: The Definitive Guide
One of the features of computer work, and this is very commonly true with Web pages and even more so when you have to deal with HTML, is that there is a lot of repetitive typing of the same fixed phrases over and over.Frontier provides a way out of such annoying repetitive labor. (After all, what's a computer for if it doesn't save you from just this kind of busy work?)
This is the Glossary mechanism. You keep a table of text substitutions; when your page is rendered, the substitutions are performed. In effect, you get to make yourself a set of shorthand abbreviations for some stock phrases. The idea is utterly simple; yet it's such a handy tool that you'll use it all the time.
To see an example of the glossary at work, go into myFirstSite.default and, where it says "thanks to Frontier", surround the word "Frontier" with quotes. Now preview the page in the browser. The word "Frontier" doesn't appear in quotes in the browser, but it has become a link, leading to the Frontier Web site at scripting.com.
The way this happens is that, at rendering time, Frontier searches for tables called #glossary, and it looks in these for entries whose name matches any quoted material in your Web page.
If it finds such an entry, it substitutes the value of the entry for the quoted material in the page. If it doesn't find such an entry, it just leaves the original quoted material alone. Before it gives up, it looks in user.html.glossary. That's where it found the entry for "Frontier" -- take a look at it.
You can see that user.html.glossary.Frontier has a value which is an <a> tag, the word "Frontier", and the closing </a> tag; this is what eventually made its way into the rendered version of our default page.
You can prevent any particular quoted phrase in your page from being searched as a glossary item by putting a backslash before the first and last quotation mark. For instance, if you say this in myFirstSite.default:
Why is the program called \"Frontier\"?Then when you preview in the browser you just see "Frontier" in quotes. (The reason you have to signal both the first and last quotation mark in this way is so that you can include quotes inside a quoted string. Without this mechanism, Frontier would have difficulty knowing where a quotation ends.)
You can also turn off the whole glossary mechanism, for one page or a group of pages, by means of the #expandGlossaryItems directive; this is true by default, but you can set it to false.
Things in angle-brackets (HTML tags) are normally protected from having their contents seen as possible glossary items; things could get pretty crazy otherwise.
Links, such as the entries in user.html.glossary, may not be the only sorts of things you use glossaries for. You'll doubtless find many uses for the glossary mechanism, since many kinds of boilerplate or repetition are likely to occur throughout your pages. People's tastes and needs vary.
Of course you can create glossary items manually; they're just table entries.On Mac OS, you also get a shortcut from within your browser to build glossary entries like "Frontier" and the others already in user.html.glossary.
When Frontier is running, the browser has an extra Scripts menu containing an item Add To Glossary, from which you can insert into user.html.glossary a reference to the page you're currently looking at in the browser. (User.html.glossary may not be where you ultimately want to keep the reference, but it is a good initial storage location; you can easily cut and paste the entry to another glossary table later if you like.)
You can also use items in the Scripts menu to get quickly to user.html.glossary, and even to see user.html.glossary converted into an actual page of links in the browser.
An interesting problem arises with the link glossary entries in user.html.glossary -- you're restricted to one fixed phrase which is going to appear between the <a> and the </a> tags.For example, right now the glossary item "Frontier" resolves to a link emanating from the word "Frontier". It would be nice to have more flexibility about what text the link emanates from.
The solution is the glossSub macro call. (I'm particularly fond of the glossSub script, because I originally conceived and wrote it!) It is specifically intended for glossary entries that are <a> links, such as user.html.glossary.Frontier. With glossSub, two things must appear in the parentheses -- the name of the glossary entry, as it would appear if you weren't using glossSub, and the text you want the link to emanate from. So, for instance:
There is a {glossSub("Frontier", "really cool tool")} you should know about.That ends up saying: "There is a really cool tool you should know about.", with the link to the Frontier site emanating from the words "really cool tool". Modify myFirstSite.default by adding that sentence, and preview that in the browser. Getting the idea?
By the same token, you can supply an imageRef() call as the second parameter in a glossSub macro call, to make a clickable image -- that is, a link which goes to the URL given in the glossary link entry, but emanates from an image.For example, somewhere in myFirstSite.default(), put this:
<p>Click here: {glossSub("Frontier", imageRef("site"))}</p>When you preview this in the browser, you find that this is indeed a clickable image leading to the Frontier Web site.
Actually, there is another syntax that accomplishes much the same thing, and is often more convenient. Instead of a glossSub macro call, supply a glossRef parameter to an imageRef call, whose value is the name of a glossary link, like this:
<p>Click here: {imageRef("site", glossRef:"Frontier")}</p>
The behavior of the glossary mechanism, in the way it searches for each quoted phrase as a glossary entry, is really special -- nothing else in the Web site management tools acts quite like this. So let's be clear about it, so you can take full advantage of it!First, your page can have a special glossary of its own. This can be anywhere in the database. Just use a #glossary directive in the page:
#glossary "workspace.mySpecialGlossary"Next, we look for a glossary table in the same table as the page we're rendering. Then in the table that contains that, and so on. And we always look in user.html.glossary last.
So, if myFirstSite has a sub-table called someFolder, and you're rendering a page in it called myPage, which has the #glossary directive above, then for each glossary item in myPage:
As soon as we find the item we're looking for, we stop looking and perform the substitution. You can use this to give glossaries the same hierarchical object-oriented power as directives and images.
- First we look in workspace.mySpecialGlossary
- Then we look in websites.myFirstSite.someFolder.#glossary (if there is one)
- Then we look in websites.myFirstSite.#glossary (if there is one)
- Then we look in websites.#glossary (if there is one)
- Ultimately we look in user.html.glossary
At this point a word is in order about the relationship between glossary items and macros.Perhaps you noticed while doing the Images exercise that typing the imageRef call was rather a pain. If you wanted to include the same imageRef call at several places in your page or site, things might become particularly trying.
This comes up for me all the time, such as when I have a list of items and some of them are marked with a little GIF that says "new" or "cool". I don't want to have to write a whole imageRef call for every occurrence of this GIF; I want to just put "new" or "cool" and have the glossary put the imageRef call in for me.
In other words: can a glossary item consist of a macro call?
Yes, it can. To see this for yourself, go into the template, and select the entire imageRef call, including the curly braces at both ends.
Cut, and now type "ourLogo", including the quotes, thus replacing the macro call with a glossary reference. Go into myFirstSite.#glossary (ignoring anything that may be in there; I'll explain all that later), and from the Table menu use New Scalar to create a new String.
Call the string "ourLogo" (without the quotes), tab into its value, and Paste (and hit Enter to set it). Now go to myFirstSite.default, and preview it in the browser.
It works: "ourLogo" has been interpreted as {imageRef("site")}, and this in turn has been interpreted to give the desired <img> tag, which shows up in the browser as the actual image.
The rule is this: if the entire value of a glossary item appears to be a macro call -- because it begins with a left curly brace and ends with a right curly brace -- then, when the glossary reference is resolved, the macro is evaluated.
Observe that this is a highly specialized situation. If you merely include a macro call somewhere within the value of a glossary item, that macro will not be evaluated. The glossary item must consist entirely of a macro call in order for the macro to be evaluated.
The opposite (or perhaps I should say, the inside-out) is also true. If the result of evaluating a macro call appears to be a possible glossary reference -- because it begins with a double-quote and ends with a double-quote -- then, when the macro call is evaluated, the glossary reference is also resolved.
To see this in action, here's an utterly ridiculous example. Where myFirstSite.default says (or used to say) "thanks to Frontier", make it say this:
thanks to {displaystring("fron" + "tier")}Preview in the browser; sure enough, there's our link to the UserLand site, emanating from the word "Frontier". What happened is that the result of the macro was the quoted string "Frontier"; this in turn was resolved as a glossary item, and here we are.
All text is by Matt Neuburg, phd, matt@tidbits.com.
For information about the book Frontier: The Definitive Guide, see my home page:
http://www.tidbits.com/matt
All text copyright Matt Neuburg, 1997 and 1998. ALL RIGHTS RESERVED.
No one else has any right to copy or reproduce in
any form, including electronic. You may download this material but you may not post it for others to
see or distribute it to others without explicit permission from the author.
Downloadable versions at http://www.ojai.net/matt/downloads/webTutorial.hqx and http://www.ojai.net/matt/downloads/webTutorial.zip.
Please do not confuse this tutorial with a certain other Frontier 5 tutorial based upon my earlier work.
This page created with
Frontier, 2/11/2000; 6:59:53 PM.