THIS IS HISTORY! Check fabien.benetou.fr for news.

Seedea, scalable creativity

Xye, consultancy for serious creators

Information

RSS

(Updates)

authors (advanced)

The {(...)} "expression markup" allows for a variety of string and formatting operations to be performed from within markup. Operations defined by this recipe include substr, ftime, strlen, rand, toupper, tolower, ucfirst, ucwords, pagename, and asspaced.

Markup Expressions were introduced in PmWiki 2.2.0-beta43.

substr

The "substr" expression extracts portions of a string. The first argument is the string to be processed, the second argument is the initial position of the substring, and the third argument is the number of characters to extract. Note that the initial position argument is zero-based (i.e., the first character is referenced via a "0").

 {(substr "PmWiki" 2 3)}
 {(substr "PmWiki" 2)}
 {(substr "PmWiki" 0 1)}
 Wik
 Wiki
 P

ftime

"Ftime" expressions are used for date and time formatting. The generic form is

{(ftime "fmt" "when")}
{(ftime fmt="fmt" when="when")}

where fmt is a formatting string and when is the time to be formatted. The arguments can be in either order and may use the optional "fmt=" and "when=" labels.

Examples:

 {(ftime fmt="%F %H:%M")}
 {(ftime %Y)}
 {(ftime fmt=%F)}
 {(ftime yesterday)}
 {(ftime when=tomorrow)}
 {(ftime %F yesterday)}
 {(ftime week %F)}
 {(ftime fmt=%F month)}
 2024-11-19 04:25
 2024
 2024-11-19
 November 18, 2024, at 12:00 AM
 November 20, 2024, at 12:00 AM
 2024-11-18
 1970-01-01
 1970-01-01

The fmt parameter is whatever is given by "fmt=", the first parameter containing a '%', or else the site's default. The formatting codes are described at http://www.php.net/strftime. Some common formatting strings:

     %F                # ISO-8601 dates      "2024-11-19"
     %H:%M:%S          # time as hh:mm:ss    "04:25:45"
     %m/%d/%Y          # date as mm/dd/yyyy  "11/19/2024"
     "%A, %B %d, %Y"   # in words            "Tuesday, November 19, 2024"

The when parameter understands many different date formats. The when parameter is whatever is given by "when=", or whatever parameter remains after determining the format parameter. Some examples:

    2007-04-11            # ISO-8601 dates
    20070411              # dates without hyphens, slashes, or dots
    2007-03               # months
    @1176304315           # Unix timestamps (seconds since 1-Jan-1970 00:00 UTC)
    now                   # the current time
    today                 # today @ 00:00:00
    yesterday             # yesterday @ 00:00:00
    "next Monday"         # relative dates
    "last Thursday"       # relative dates
    "-3 days"             # three days ago
    "+2 weeks"            # two weeks from now
    "2007-04-11 -4 days"  # four days before April 11

The when parameter uses PHP's strtotime function to convert date strings according to the GNU date input formats; as of this writing it only understands English phrases in date specifications.

The variable $FTimeFmt can be used to override the default date format used by the "ftime" function. The default $FTimeFmt is $TimeFmt.

strlen

The "strlen" expression returns the length of a string. The first argument is the string to be measured.

 {(strlen "{$:Summary}")}
 18

rand

The "rand" expression returns a random integer. The first argument is the minimum number to be returned and the second argument is the maximum number to be returned. If called without the optional min, max arguments rand() returns a pseudo-random integer between 0 and RAND_MAX. If you want a random number between 5 and 15 (inclusive), for example, use rand (5, 15).

 {(rand)}
 893718436

toupper / tolower

The "toupper" and "tolower" expressions convert a string into uppercase or lowercase. The first argument is the string to be processed.

 {(toupper "{$:Summary}")}
 {(tolower "{$:Summary}")}
 MARKUP EXPRESSIONS
 markup expressions

ucfirst

The "ucfirst" expression converts the first character of a string to uppercase. The first argument is the string to be processed.

 {(ucfirst "{$:Summary}")}
 Markup expressions

ucwords

The "ucwords" expression converts the first character of each word in a string to uppercase. The first argument is the string to be processed.

 {(ucwords "{$:Summary}")}
 Markup Expressions

pagename

The "pagename" expression builds a pagename from a string. The first argument is the string to be processed.

asspaced

The "asspaced" expression formats wikiwords. The first argument is the string to be processed.

Nesting expressions

Markup expressions can be nested:

 {(tolower (substr "Hello World" 2))}
 llo world

Notes

<< | Documentation Index | >>


This page may have a more recent version on pmwiki.org: PmWiki:MarkupExpressions, and a talk page: PmWiki:MarkupExpressions-Talk.

Page last modified on May 26, 2007, at 08:56 PM