The globals model allows you to define constants that can be used throughout your website. Globals should be used to define information that tends to change periodically over time, especially if the information is repeated more than once throughout your site.  Suppose your business "tag line" (slogan) is repeated on various pages throughout your site. If your tag line ever changes you might have to update dozens of pages and there is a risk that you might overlook some of the pages that should be updated. On the other hand, if the tag line is defined as a global you would use the $global function whenever you want to show the tag line on your site. With this configuration you simply need to update the globals definition if your tag line ever changes.

Defining globals

Most small sites will likely only need one globals definition. In this case, you don't need to supply a name when using the stow command and the name of the definition will be defaulted to globals. On the other hand, if you have a lot of global variables it is better to group them into separate definitions whose values will tend to be used together. For example, a law firm might define a distinct globals category to store their rates for various services. Here we see an example, let's assume this is stowed under the name rates. In this case, rates becomes the name of the category that you will use to retrieve the globals.

Globals rates table

Note that the Global Values can contain $functions. If fact, another reason you might want to use globals is to encapsulate complex dollar functions. Suppose you are building a site that sells products in US dollars to US customers and Canadian Dollars to Canadian customers. You could define a global such as the following:

Currency global

In this nested dollar function $site(tld) might resolve to .ca or .com, depending on which site the visitor is on. This value is used by the $if function to render either Canadian Dollars of US Dollars.

Rendering Globals

Globals are rendered using the $global function. This function has one required parameter and two optional parameters as described here:

  1. The name of the global variable to be rendered.
  2. The value to be rendered if the global is not defined. This defaults to an empty string.
  3. The category under which the global is defined. This defaults to globals.

A page on the law firm's site that defined the rates globals might include content such as:

Our rate for an office consultation 
is $global(office_consultation,,rates).

Notice there are two $ symbols. The first $ symbol is there because we want to show the rate in dollars.

Referring back to the currency global, assuming this is defined in the default globals definition your product pages could include something like:

All of our prices are shown 
in $global(currency).

Centralizing Company Information

If you are considering using the globals model to define things like your Company Name, Address, Phone Number, Office Hours, etc. a better option is to use the local_business model.

Sample globals definition
🡇
Sample rendered code