Next Chapter | Up | Next Section | Contents

Custom, Special, C, and Empty Formats


A custom format is used for the output of objects. The value of a custom format is the method name evaluated upon the object to be inserted. The method should return an object that, when converted to a string, yields the desired text. For example, the DTML source text:

<dtml-var date fmt=DayOfWeek>

inserts the result of calling the method, DayOfWeek, with the value of the variable date . As the example suggests, the most common use of custom formats in Zope is in the output of date-time data. The appendix A provides a summary of the custom formats available for date-time data.

In addition to custom formats, a few special formats are defined by the var tag that can be used with the fmt attribute. These are summarized in table 16.

Special formats that may be used with the var tag fmt attribute

Special Format

Description

whole-dollars

Show a numeric value with a dollar symbol.

dollars-and-cents

Show a numeric value with a dollar symbol and two decimal places.

collection-length

Get the length of a collection of objects.

structured-text

Allows use of structured text as a special format.

In addition to custom and special formats, C11-style formats may also be used. A C-style format consists of text containing a single conversion specification. A conversion specification consists of a percent sign, optionally followed by a flag, a field width, a precision value, and a conversion specifier. A description of C-style formats is beyond the scope of this document. For details on C-style formats, see a C-language reference manual. Not all conversion specifiers are supported by DTML. Table 17 summarizes the conversion specifiers that DTML does support.

C-style specifiers for the fmt attribute

Code

Description

d

Signed decimal integers

e

Scientific notation

E

Scientific notation (uppercase E)

f

Decimal floating point

g

Shorter of e or f

G

Shorter of E or F

I

Signed decimal integers

o

Unsigned octal

s

String of characters

u

Unsigned decimal integers

x

Unsigned hexadecimal lowercase

X

Unsigned hexadecimal uppercase

Next Chapter | Up | Next Section | Contents