version=pmwiki-2.2.68 ordered=1 urlencoded=1
author=simon
charset=UTF-8
csum=nesting
ctime=1176718061
name=PmWiki.MarkupExpressions
rev=80
targets=PmWiki.PageListTemplates,PmWiki.PageLists,PmWiki.WikiStyles,PmWiki.ConditionalMarkup,PmWiki.PageVariables,PmWiki.PageTextVariables,Cookbook.MarkupExpressionSamples,Cookbook.MarkupExprPlus
text=(:Summary:String and formatting operations:)%0a(:Audience: authors (advanced) :)%0a%0aThe [@{(...)}@] "expression markup" allows for a variety of string and formatting operations to be performed from within markup.  Operations defined by this recipe include ''[[#substr|substr]]'', ''[[#ftime|ftime]]'', ''[[#strlen|strlen]]'', ''[[#rand|rand]]'', ''[[#mod|mod]]'', ''[[#to|toupper / tolower]]'', ''[[#ucfirst|ucfirst]]'', ''[[#ucwords|ucwords]]'', ''[[#pagename|pagename]]'' and ''[[#asspaced|asspaced]]''.%0aMarkup expressions can be [[#nesting|nested]], using the markup [@{(...(...)...)}@].%0a%0a[[#substr]]%0a!! ''substr''%0a%0aThe "substr" expression extracts portions of a string.  The arguments are%0a# the string to be processed. Always quote the string to be processed.%0a# the initial position of the substring.  Note that the initial position argument is zero-based (i.e., the first character is referenced via a "0").%0a# the number of characters to extract%0a(:markup class="horiz":)%0a {(substr "PmWiki" 2 3)}%0a {(substr "PmWiki" 2)}%0a {(substr "PmWiki" 0 1)}%0a {(substr "PmWiki" 0 -3)}%0a {(substr "PmWiki" -3)}%0a(:markupend:)%0a%0aTo obtain the last n characters of a string use [@{(substr "string" -n)}@]%0a[[%3c%3c]]%0aTo truncate the last n characters of a string use [@(substr "string" 0 -n)}@]%0a%0a[[#ftime]]%0a!! ''ftime''%0a%0a"Ftime" expressions are used for date and time formatting.  The generic form is%0a%0a->[@{(ftime "fmt" "when")}@]%0a->[@{(ftime fmt="fmt" when="when")}@]%0a%0awhere ''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.%0a%0aExamples:%0a(:markup class="horiz":)%0a {(ftime)}%0a {(ftime fmt="%25F %25H:%25M")}%0a {(ftime %25Y)}%0a {(ftime fmt=%25T)}%0a {(ftime when=tomorrow)}%0a {(ftime fmt="%25Y-%25m-%25d" yesterday)}%0a {(ftime "+1 week" %25F)}%0a {(ftime fmt=%25D "+1 month")}%0a {(ftime fmt="%25a%25e %25b" when="next week")}%0a(:markupend:)%0a%0aThe ''fmt'' parameter is whatever is given by "fmt=", the first parameter containing a '%25', or else the site's default. The formatting codes are described at %25newwin%25 http://php.net/strftime. In addition to those, [='%25F'=] produces ISO-8601 dates, and '%25s' produces Unix timestamps.%0aSome common formatting strings:%0a%0a    [= %25F            =]    # ISO-8601 dates      "{(ftime %25F)}"%0a    [= %25s            =]    # Unix timestamp      "{(ftime %25s)}"%0a    [= %25H:%25M:%25S      =]    # time as hh:mm:ss    "{(ftime %25H:%25M:%25S)}"%0a    [= %25m/%25d/%25Y      =]    # date as mm/dd/yyyy  "{(ftime %25m/%25d/%25Y)}"%0a    [= "%25A, %25B %25d, %25Y" =]  # in words            "{(ftime "%25A, %25B %25d, %25Y")}"%0a%0aThe ''when'' parameter understands many different date %25newwin%25[[http://php.net/manual/en/datetime.formats.php|formats]].  The when parameter is whatever is given by "when=", or whatever parameter remains after determining the format parameter.  Some examples:%0a%0a    2007-04-11            # ISO-8601 dates%0a    20070411              # dates without hyphens, slashes, or dots%0a    2007-03               # months%0a    @1176304315           # Unix timestamps (seconds since 1-Jan-1970 00:00 UTC)%0a    now                   # the current time%0a    today                 # today @ 00:00:00%0a    yesterday             # yesterday @ 00:00:00%0a    "next Monday"         # relative dates%0a    "last Thursday"       # relative dates%0a    "-3 days"             # three days ago%0a    "+2 weeks"            # two weeks from now%0a%0a'''Note:''' If you want to convert a Unix timestamp you '''must''' prefix with the @. Thus, [@"{(ftime "%25A, %25B %25d, %25Y" @1231116927)}"@].%0a%0aThe ''when'' parameter uses PHP's %25newwin%25[[(http://www.php.net/)strtotime]] function to convert date strings according to the GNU [[http://www.gnu.org/software/tar/manual/html_node/Date-input-formats.html|date input formats]]; as of this writing it only understands English phrases in date specifications.%0a%0aThe variable $FTimeFmt can be used to override the default date format used by the "ftime" function.  The default $FTimeFmt is $TimeFmt.%0a%0a[[#strlen]]%0a!! ''strlen''%0a%0aThe "strlen" expression returns the length of a string.  The first argument is the string to be measured.%0a%0a(:markup class="horiz":)%0a {(strlen "{$:Summary}")}%0a(:markupend:)%0a%0a[[#rand]]%0a!! ''rand''%0a%0aThe "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).%0a%0a(:markup class="horiz":)%0a {(rand)}%0a {(rand 1 99)}%0a(:markupend:)%0a%0a[[#mod]]%0a!! ''mod''%0a%0aThe advanced "mod" expression returns the modulo (remainder) of the division of two numbers. It may be used in advanced [[PageList templates]] together with [@{$$PageCount}@] to insert markup every (modulo) entries, for example to create alternate styled "zebra" table rows, or to insert a line/row break. (See also [[PageLists]], [[WikiStyles]] and [[ConditionalMarkup]].)%0a%0a(:markup class="horiz":)[@%0a>>comment%3c%3c%0a%25define=bg1 item bgcolor=#f88%25%0a%25define=bg2 item bgcolor=#ff8%25%0a%25define=bg0 item bgcolor=#8f8%25%0a[[#altrows]]%0a* %25bg{(mod {$$PageCount} 3)}%25 {=$Name} ({$$PageCount})%0a[[#altrowsend]]%0a>>%3c%3c%0a(:pagelist fmt=#altrows group=PmWiki count=10:)%0a@]%0a%0a[[#to]]%0a!! ''toupper'' / ''tolower''%0a%0aThe "toupper" and "tolower" expressions convert a string into uppercase or lowercase.  The first argument is the string to be processed.%0a%0a(:markup class="horiz":)%0a {(toupper "{$:Summary}")}%0a {(tolower "{$:Summary}")}%0a(:markupend:)%0a%0a[[#ucfirst]][[#ucwords]]%0a!!''ucfirst'' / ''ucwords''%0a%0aThe "ucfirst" expression converts to uppercase the first character of the string, and "ucwords", the first character of each word. The first argument is the string to be processed.%0a%0a(:markup class="horiz":)%0a {(ucfirst "{$:Summary}")}%0a {(ucwords "{$:Summary}")}%0a(:markupend:)%0a%0a%0a[[#pagename]]%0a!! ''pagename''%0a%0aThe "pagename" expression builds a pagename from a string.  The first argument is the string to be processed.%0a%0a(:markup class="horiz":)%0a {(pagename "{$:Summary}")}%0a(:markupend:)%0a%0a[[#asspaced]]%0a!! ''asspaced''%0a%0aThe "asspaced" expression formats wikiwords.  The first argument is the string to be processed.%0a%0a(:markup class="horiz":)%0a {(asspaced "{$FullName}")}%0a(:markupend:)%0a%0a[[#nesting]]%0a!! Nesting expressions%0a%0aMarkup expressions can be nested. Omit the curly braces for the inner expressions:%0a%0a(:markup class="horiz":)%0a {(tolower (substr "Hello World" 2))}%0a(:markupend:)%0a%0a[[#notes]]    %0a!! Notes%0a%0a* For PmWikis version 2.2.33 or older, the string-processing expressions may not work properly on multibyte UTF-8 characters. Newer versions should work fine.%0a%0a!! See also%0a* [[Page variables]], [[Page text variables]]%0a* [[Conditional markup]]%0a* Cookbook:MarkupExpressionSamples &mdash; '-custom markup expression samples-'%0a* Cookbook:MarkupExprPlus
time=1409816555
