Rules enable you to tell CatBase how to make decisions about publishing and styling your data according to certain criteria that you choose.
Creating a Rule
To create a new Rule:
Create or edit a Publishing Stylesheet.
Create or modify a Paragraph.
Add a new Element to the Paragraph.
Select the Element Type: Rule
Click the Edit Rule button. The Rule window looks like this:
Rules are based on the logic:
IF (something is true) THEN (do something) OTHERWISE (do something else) AND ALSO (optionally do something else as well)
There are four areas in the Rule dialog:
The first area in the Rule window is the IF area:
This is where you select your criterion for the Rule.
Start by choosing the selection criterion from the first popup:
IF The field:
Select this option to base your Rule on the contents of a field.
IF It's the first record in the selection
The Selection refers to the group of records being published at that moment. So this could mean various things:
If the data is being organised into Categories, the Selection refers to the records in the current Category.
If the data is from a related table, the Selection refers to the group of related records.
If the data is not organised into Categories, the Selection refers to the whole group of records being published.
For example ...
When the data is organised into Categories
In this case, CatBase sorts the Categories (and, if appropriate, sub-categories) according to your specification (most often by Category Name). It then steps through the Categories, finds all the records that go under each Category, sorts those records as you've specified, and publishes them. Suppose, for example, that you're publishing a membership directory and you want the first member in each Category to have their name set in a different stylesheet to the other members in the same Category. You might create a Rule like this:
Note the Style for paragraph option has been selected, and the "first in category" Stylesheet.
In the Otherwise tab, the Publish the Field: name option has been selected. As each record is published, the Rule is evaluated. If it's the first record in the category, then the "irst in category" Paragraph Stylesheet is applied to the name; otherwise, the default style for the Paragraph is used.
When the data is from a related table:
In this case, each group of related records is a Selection. For example, let's suppose you are publishing a catalogue of products that have parts related to them; each Product can have any number of Parts, and those Parts are listed after the product picture. Each Product's list of Parts is a Selection.
When the data is not sorted by category, or from a related table:
In this case the complete group of records being published constitutes the Selection.
IF it's the last record in the record in the selection
This is the same as the "first record in the selection" except that it applies to the LAST record.
IF it's an odd number within the selection
A typical use for this option is when you want to have alternating records formatted differently - for example, left-aligned, right-aligned, etc. You can create a Rule to tell CatBase to apply a different Stylesheet if it's an odd-numbered record within the Selection (see above for a discussion of Selections).
IF it's an even number within the selection
Like an odd-numbered record, but applies to the even-numbered ones.
IF the number of records within the selection:
When you choose this option, the display changes:
Suppose you are publishing a directory of Companies and you want to flag whether they have multiple locations or not. The locations are in a related table. If they have only one location (ie, one related Locations record) you want to publish a comment; if they have more than one Location record, you want to publish a different comment. You could create a Rule like this:
IF the Paragraph is longer than ...
When you choose this option, the display changes:
This refers to the length of the current Paragraph at the point where the Rule is encountered - not the overall length of the Paragraph.
For example, maybe you are publishing a personnel directory. On the first line of each entry you want to publish the person's last name, a comma and a space, then their first name, another comma and space, then their business title. But if their complete name is longer than, say, 30 characters, you want their business title to go onto the next line. Your Paragraph would consist of 6 Elements:
Field: Last name
Text: comma and space
Field: First name
Text: comma and space
Rule: "IF the paragraph is longer than 30 characters, THEN publish punctuation Soft Return"
Field: Business title
IF the script variable
Choose this option and the display changes:
A Variable is a value that can change. Specifically, a Script Variable is a value that can be entered into a Publishing Project for use by scripts and Rules.
For example, suppose that you are publishing a membership directory, and you need to create several different versions for different languages. The main content (names, addresses, telephone numbers etc.) will not change, but there is some text that does need to be language-specific. Perhaps the phone number line contains the word "Telephone", and this needs to be translated for each language. It would be tedious to create a different Publishing Stylesheet for each language. And if you needed to make a change to the content, you would have to remember to make that same change in all the different language versions. Instead, you can set up a Publishing Project and enter the language into the Script Variable field - for example:
Now, in your Rule you can say:
You can create as many Rules as you need - one for each language - then simply change the Script Variable in the Publishing Project as needed.
IF the category name
This option will only appear if your Publishing Stylesheet is based on Categories (ie - the data is sorted first by Category).
You can use this option to control the content or formatting depending upon which category the records are in.
For example, suppose you're publishing a catalogue of electrical components. The products are organised into categories such as "Fuses", "Cables" and so on. You want the product names to be colour-coded according to the category they are in. You could set up a Rule like this:
Note that the Style for paragraph: fuses heading option has been selected. So, when the data is published, if a product is listed under the Fuses category, its name will be set in the style "fuses heading".
IF the category number
The principle is the same as the "category name" option, but the rule is evaluated using the Category Number instead of Name.
IF the parent category number
When this option is selected, the rule is evaluated based on the "parent" category of the current category - in other words, if you have two Category levels. the top level is the "parent" to the second level.
IF the top-level category number
If you have two or more levels of category, the top level is the first level (Level 1).
IF it's the main category
When you select Categories for your data, each record can go into any number of Categories. The first one you add will be marked as the Main Category, but you can select a different one to be the Main Category by clicking on the Main Category checkbox in the list of Categories on the record's data entry form. You can create a Rule to tell CatBase to do something differently if it is/is not the main category. For example, you might want to include the product image only when the product is listed under its main category.