DiscusWare, LLC.
Download Purchase Contact Us
Home
Support Home Documentation Knowledge Base Support Forums Support Request Advanced Services
Discus Template Language :: Text operations

This document describes the manipulations to text and strings that can be invoked using the template language. 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 contains a large number of "text operations" which manipulate variables and strings into an appropriate format for display or storage. These functions are listed here in the order in which they are most used.

  1. Replacing Text with Other Text
  2. Dates and Times
  3. Upper/Lower Case Text
  4. Truncation
  5. Spacing with {...}
  6. Repeated Text
  7. Forms
  8. Escape/Unescape Text
  9. HTML Operations
  10. CSS Compatibility
  11. Word Wrapping
  12. Space Padding
Replacing Text with Other Text

It is common to replace one bit of text with another bit of text. The Discus Template Language allows you to do this directly from within the templates. Your operation is on a variable, and the following must appear on a line of its own:

<#replace "old_text" with "new_text" in $variable#>

The above code replaces ALL occurrences of old_text with new_text in $variable. The replacement is case-INsensitive. You are free to use variables in place of old_text and new_text as necessary.

<#define $text = "Discus is bad software"#>
<#replace "bad" with "good" in $text#>
$text

Discus is good software

Dates and Times

It is a common operation to convert from a unix time (expressed as the number of seconds since January 1, 1970) into a human-readable format. The Discus Template Language date function allows you to perform many manipulations of the date format in performing these conversions. The time at which this document was written is December 19, 2001 at 2:44:50 PM. In the unix time format, this is 1008794690. The date command is used to convert this into a human-readable format:

<#date unix_time_format_date format "human readable date format"#>

The following variables can be used when setting up the human readable date format string:

    Variable Meaning Example
    %weekday Day of the week from language.conf Wednesday
    %wkdy. Abbreviated weekday from language.conf Wed.
    %wkdy_ Abbreviated weekday from language.conf, no period Wed
    %hour Hour of the day, in 12-hour (AM/PM) format 10
    %24hour Hour of the day, in 24-hour format 22
    %minute The number of minutes 44
    %second The number of seconds 12
    %ampm Whether it is AM or PM am
    %month Name of the month from language.conf December
    %mon. Abbreviated month from language.conf Dec.
    %mon_ Abbreviated month from language.conf, no period Dec
    %nmonth Number of the month 12
    %day Number of the day 19
    %year Number of the year in 4-digit format 2001
    %2year Number of the year in 2-digit format 01

Commonly, the date format is derived from the language.conf file by defining it with a variable, such as $L{LONG_DATE}. Here are some examples of how the date command is used to operate on the time 1008794690.

<#date 1008794690 format "%day/%mon_/%year:%24hour:%minute:%second"#>
<#date 1008794690 format "%wkdy_ %mon_ %day %24hour:%minute:%second CST %year"#>
<#date 1008794690 format "%mon_ %day %24hour:%minute:%second CST %year"#>

19/Dec/2001:14:44:50
Wed Dec 19 14:44:50 CST 2001
Dec 19 14:44:50

Note that you can include text (commonly HTML formatting) within the date format string. As long as this is not identical to a recognized variable, your text will survive the date conversion. Note that "CST" in the second example, as well as all of the spaces within the formats, are all simply passed through.

There are two other functions that are related to time and date:

    Pattern Meaning
    <#current time#> Server's current time in unix time format
    <#gmtoffset#> Number of seconds by which your server's local time differs from GMT time
Upper/Lower Case Text

It is often useful to capitalize a word. You can also ensure that the first letter of a word is lower case.

<#define $text = "discus Pro"#>
\u$text
\lDISCUSSION BOARD

Discus Pro
dISCUSSION BOARD

Truncation

The Discus Template Language allows you to truncate text to a certain number of characters. You can do this by simply disregarding any of the text after your character limit, or by adding characters (such as "...") at the end of the truncated text if it exceeds the limit.

The Template Language is intelligent in that it counts characters based on the number of characters displayed, not the number of characters in the string. For example, the string "Hello <b>world</b>" (without the quotes) counts as 11 characters (the <b> and </b>) do not count, since they do not make the display any longer. As another example, the string "1&nbsp;2" (without the quotes) counts as 3 characters (the &nbsp; displays as 1 character even though it's actually 6 characters long).

<#define $text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"#>
<#maxchar 10 $text#>
<#maxchar 15/... $text#>

ABCDEFGHIJ
ABCDEFGHIJKLMNO...

Spacing with {...}

As described in "Treatment of Spaces" in the "General Template Structure" document, the Discus Template Language collapses multiple consecutive spaces into a single space, and trims whitespace from the left and right end of the line. However, there are cases where it is desirable to force the inclusion of more than 1 consecutive space character, or where you wish to use a tab character. The following special characters force the indicated number of spaces:

{|}     ## Null (useful to separate variables if needed)
{||}    ## 1 space
{|||}   ## 2 spaces
{||||}  ## 3 spaces
...
{|tab|} ## Tab character

You can insert as many consecutive spaces as you want using the {||...||} style of code. The number of spaces you're inserting is always one less than the number of vertical bars (|) you have between the braces. The code {|||} has three vertical bars, which creates a total of two spaces between vertical bars, and thus inserts two consecutive spaces into your template.

Repeated Text

This function lets you supply text and the number of times that text is to be repeated. The text is then repeated the number of times you specify.

<#define $number = "2"#>
<#repeated 5 "Hello"#>
<#repeated $number "Good Bye "#>

HelloHelloHelloHelloHello
Good Bye Good Bye

Forms

The following functions are available to prepare and manipulate data presented on forms.

<#form escape "text"#>

This function converts characters within text into their HTML equivalents so that the result can be put within a FORM input or textarea box. (If the text itself contained quotation marks or HTML code, it may confuse some browsers.) The specific characters converted are, in this order: & < > " '

<#define $text = "the word "blah""#>
Without escape:
<input type=text value="$text">
With escape:
<input type=text value="<#form escape "$text"#>">

Without escape:

With escape:

Escape/Unescape Text

Escaping text ensures that it will be properly transmitted within forms. This is the same format used to format URLs. Spaces are translated to the plus sign (+), and non-alphanumeric characters are converted into a hex code equivalent. Unescaping the text is the inverse function.

<#escape "I'm testing"#>
<#unescape "I%27m+testing"#>

I%27m+testing
I'm testing

HTML Operations

Often it is necessary to remove HTML code before rendering the result in the template. This is frequently needed when preparing text for rendering via JavaScript. There are two text functions that deal with removing HTML. The "remove html" function removes all HTML code (<...> and &...; codes). The "javascript prepare" function does the same thing as the "remove html" function, except that it removes the apostrophe (') character, which browsers just can't seem to get consistently right when rendering JavaScript code.

<#define $text = "<i>Discus</i> Pro can't be beat"#>
$text
<#remove html "$text"#>
<#javascript prepare "$text"#>

Discus Pro can't be beat
Discus Pro can't be beat
Discus Pro cant be beat

CSS Compatibility

If templates or skins make use of cascading style sheets, it is often helpful to translate the user's chosen font size (on the HTML scale of size 1 to 7, or relative scale -7 to +7) into a similar font size for cascading style sheets (on a point scale like those used in word processors). The syntax below replaces a number from 1 to 7 with the appropriate CSS point size:

<#css size (2)#>
<#css size (-1)#>

8pt
10pt

Word Wrapping

The Discus Template Language has word wrapping built in. You specify the maximum number of characters per line you want and supply the text, and word wrapping automatically occurs by inserting newline characters as appropriate.

<#define $text = "word1 word2 word3 word4 word5 word6"#>
<#wordwrap 15 "$text"#>

word1 word2
word3 word4
word5 word6

Space Padding

When you are operating with a fixed-width font, it is often useful to insert a bit of text, and then an appropriate number of spaces after that text, so that the overall length of the line is constant. If the length of the line you specify is shorter than the text you are padding, then the text is truncated.

<#define $text = "1234567890"#>
<#rtpad 15 "$text"#>Test1
<#rtpad 10 "$text"#>Test2
<#rtpad 5 "$text"#>Test3

1234567890     Test1
1234567890Test2
12345Test3


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