Template code | Chunk output | |
---|---|---|
{#example_1} {!-- Available filters include perl-style regex (regular expressions). -- Let the obfuscation begin! -- -- The standard caveats apply, regex is powerful but it is often very -- difficult for your fellow humans (and even for yourself ten minutes -- on) to read your regex code. -- -- Alternate section markers are not supported. You must use the -- standard s/find/replace/[flags] syntax and not exotic variations -- like s{find}{replace}[flags] or s|find|replace|[flags] or -- s:find:replace:[flags] etc. etc. --} Please welcome {$names|s/(J)(im and )(D)(ella)/$3$2$1$4/}. {#} Theme theme = new Theme("examples"); // Fetch template from this file: themes/examples/regex.chtml // Inside that file there is a template "snippet" named #example_1 Chunk html = theme.makeChunk("regex#example_1"); html.set("names", "Jim and Della"); html.render( out ); |
![]() |
Please welcome Dim and Jella.
Please welcome Dim and Jella.
|
Template code | Chunk output | |
---|---|---|
{#example_2} {!-- -- Curly braces and pipes are safe to use *inside* your regex and -- carry the standard regex meanings. -- -- For example, this is valid: -- {$tag|s/don't lo{1,2}se your (socks|shoes)/don't lose your $1/} -- and the template engine won't mistake the first close-brace for -- the end of the tag, nor will it mistake the socks|shoes pipe as -- the start of a new filter. --} <p> {$sentence_a|s/don't lo{1,2}se your (socks|shoes)/don't lose your $1/} </p> <p> {$sentence_b|s/don't lo{1,2}se your (socks|shoes)/don't lose your $1/} </p> {#} Theme theme = new Theme("examples"); // Fetch template from this file: themes/examples/regex.chtml // Inside that file there is a template "snippet" named #example_2 Chunk html = theme.makeChunk("regex#example_2"); html.set("sentence_a", "Mama always told me, don't loose your socks in the river."); html.set("sentence_b", "Papa always told me, don't lose your shoes in the mulcher."); html.render( out ); |
![]() |
<p> Mama always told me, don't lose your socks in the river. </p> <p> Papa always told me, don't lose your shoes in the mulcher. </p> Mama always told me, don't lose your socks in the river. Papa always told me, don't lose your shoes in the mulcher. |