DiscusWare, LLC.
Download Purchase Contact Us
Home
Support Home Documentation Knowledge Base Support Forums Support Request Advanced Services
Discus Template Language :: Defining Strings & Arrays

This document describes how to define strings and arrays within templates. Unless you hold a support contract that includes support for customization, DiscusWare does not provide support for the procedures in this section.
Support Site Search
 
Manuals and Docs
  Installation
  Upgrade
  Administration - 4.0
  Administration - 3.1
  Customization
    Skin Primer
    Skin Editing
    Interface Customization
    Templates: Variables
    Templates: Substitution
    Templates: IF-THEN
    Templates: FOREACH
    Templates: FOR
    Templates: DEFINE
    Templates: Arrays
    Templates: Skins
    Templates: Text Ops
    Templates: Subroutines
    Templates: Flow Control
    Templates: Math
    Templates: Global Options
    Templates: Colors
    Templates: Language Files
Synopsis

The Discus Template Language includes a method for you to define the value of strings and arrays while a template is being processed. This also allows complex mathematical manipulations.

Definitions appear on their own line (or their own series of lines) and never within an in-line IF-THEN statement. However, definitions can be made conditionally (within block IF-THEN statements) just as you would expect. Definitions are valid within templates and within parts of skins. Re-defining a string or array is permitted; the process of re-defining wipes out all information in that definition that may have been there previously.

Defining Strings

The simplest and most common definition is to define a single string. The syntax used to do this is as follows:

<#define $variable = "Some value"#>

variable must be an alphanumeric string that will later on be replaced with the text that you are defining.

Some value is any text or other substitutions (element of a hash or array, etc.) that fit on a single line.

The simplest way to define a string is to use static text:

<#define $software_name = "Discus Pro"#>
<#define $software_descr = "best"#>
$software_name is the $software_descr discussion software available.

Discus Pro is the best discussion software available.

More useful is to use substitutions of variables:

<#define $board_title = "&quot;$DCONF->{title}&quot;"#>
Your board's title is: $board_title

Your board's title is: "Discussion Board"

Many examples of definitions of strings can be found in the Discus templates and skins.

Defining Arrays

It is possible to define arrays using the <#define array...#> syntax. The first line of this syntax contains the name of the array and the components thereof. Subsequent lines define each component of each element of the array. The final line closes the definition to return to normal processing. The component of each element is separated by a TAB character, which in these examples will be displayed as [tab].

<#define array @subcolors (_index, color)#>
1[tab]#e3e3e3
2[tab]#d0d0d0
<#/define#>

The above code defines the array @subcolors. If you were to iterate over this array with a FOREACH statement, you would get:

<#foreach $subcol (@subcolors)#>
  Color $subcol->{_index} is $subcol->{color}
<#/endloop#>

Color 1 is #e3e3e3
Color 2 is #d0d0d0

The component _index has special meaning. If defined, this is the actual number of the element in the array. If not defined, the elements in the array are added sequentially. For clarity, DiscusWare recommends and ourselves code the index in all array definitions.

Limited conditional processing is permitted when defining arrays. Rules for defining arrays are as follows:

  1. Components of an array are separated by TAB characters. There is no need to add trailing tabs at the end of lines in the case that certain components of the element do not need to be defined.

  2. You cannot define strings or other arrays in the middle of defining an array.

  3. You cannot use block IF-THEN statements when defining an array.

  4. You cannot use FOREACH or FOR loops when defining an array.

  5. You can use a single IF-THEN condition to decide whether or not to define a particular element of an array (see example below). If the condition evaluates true, the element is defined.

  6. You can use normal variable substitutions within any of the components of the array.

Here is an actual example from the section of code that builds up the main menu within the Discus administration program:

<#define array @menu (icons, color, auth, name, url, target, proonly)#>
$treeg[tab]#000000[tab][tab]Administration
$treee$treeg[tab]#0000aa[tab][tab]Navigation
$treei$treee$treem[tab]#0000aa[tab][tab]Return to Board[tab]$board_url[tab]_top
$treei$treee$treem[tab]#0000aa[tab][tab]Log In Again[tab]$admin_url[tab]_top
$treei$treef$treek[tab]#0000aa[tab][tab]Log Out[tab]$cgiurl?action=logout[tab]_top
...
# The following is all on one line...
<#if $GLOBAL_OPTIONS->{enable_debugging}#>[tab]...
...
<#/define#>

The final line demonstrates using a conditional statement to decide whether or not to define the array. The conditional statement goes first on the line and is set apart from the rest of the line by a tab. If the statement evaluates true (in this case, if the global option 'enable_debugging' is turned on), the element will be defined.

Defining with Math

It is also possible to define a variable as a mathematical computation involving other variables or constants. This is essentially a string definition (subject to all of the same rules applicable when defining a string).

<#mathdefine: $variable = "mathematical statements"#>

variable is an alphanumeric name of the variable.

mathematical statements are mathematical expressions that are evaluated to define the variable. These expressions are similar to spreadsheet functions, in that each function takes arguments and functions are evaluated from the inside out. Available functions include:

    Function Function(a) Function(a,b) Function(a,b,c)
    sum a a+b a+b+c
    plus a a+b a+b+c
    diff a a-b (a-b)-c
    minus a a-b (a-b)-c
    prod a a*b a*b*c
    product a a*b a*b*c
    times a a*b a*b*c
    quot a a/b (a/b)/c
    quotient a a/b (a/b)/c
    divide a a/b (a/b)/c
    mod a a mod b (a mod b) mod c
    modulus a a mod b (a mod b) mod c
    raise a ab abc
    int Integer of a - -

For example, sum(1,1) means 1+1 which equals 2. diff(3,2,1) means (3-2)-1 which equals zero. prod(5,6,7,2,5,0,3,4) means 5*6*7*2*5*0*3*4 which equals 0. quot(4,0) is 4 divided by zero; since the division by zero is never performed, this evaluates to 4. And int(3.14) returns 3.

You can perform several mathematical operations at once by nesting commands. For example, sum(1,diff(7-5)) means 1+(7-5) which equals 3. Getting very sophistocated, times(sum(1,2),quot(10,5)) is (1+2)*(10/5) which is 6.

Putting it all together, do you get the same result we did in this example?

<#mathdefine: $x = "int(quot(sum(prod(1,2,3),quot(4,2,0),diff(5,5)),3)"#>
$x

2

In the case of quotients (division) or modulus, the quotient or modulus is not taken if the denominator is zero.


Download Purchase Contact Us
Privacy Policy
Copyright © 2005, DiscusWare, LLC, All Rights Reserved