#*

A template for testing CamlTemplate.

$Id: coleridge.tmpl,v 1.20 2004-09-02 21:14:18 ben Exp $

*#

#open ("macro.tmpl")

  ${title}

${title}

#set (birthdate = poet.birthdate)

Here are some excerpts from poems by ${poet.name}, who was born on
#formatDate (birthdate.year, birthdate.month, birthdate.day).

       Title
       Year
       Poet's age at time of writing
       Excerpt

    #set (bgcolor = "white")

    #foreach (poem in poems)
      <tr bgcolor="${bgcolor}">
        <td>${poem.title}</td>
        <td>${poem.year}</td>
        <td>${poem.year - birthdate.year}</td>
        <td>${poem.excerpt}</td>
      </tr>

      #if (bgcolor == "white")
        #set (bgcolor = "yellow")
      #else
        #set (bgcolor = "white")
      #end
    #end
  

Some expressions:

       Expression
       Value

       48 * -3 + 12 - 1 / 6
       ${48 * -3 + 12 - 1 / 6}

    <tr>
      <td>(48 * (-3 + (12 - 1))) / 6</td>
      <td>${(48 * (-3 + (12 - 1))) / 6}</td>
    </tr>

    <tr>
      <td>(48 * (-3.45 + (12 - 1))) / 6.7</td>
      <td>${(48 * (-3.45 + (12 - 1))) / 6.7}</td>
    </tr>

    <tr>
      <td>"Poems by " + poet.name</td>
      <td>${"Poems by " + poet.name}</td>
    </tr>

    <tr>
      <td>"Poems by \"" + poet.name + "\""</td>
      <td>${"Poems by \"" + poet.name + "\""}</td>
    </tr>

    <tr>
      <td>substring("Hello, world", 7, 5)</td>
      <td>${substring("Hello, world", 7, 5)}</td>
    </tr>
  

Scalar values are true if they exist and are non-zero or non-empty;
list and hash values are true if they exist:

#set (empty = "")

#if (foo)
  You won't see this line.
#elseif (empty || 0)
  Or this one.
#elseif (poems && title && poet)
  This line will be included.
#else#
  And this one won't.
#end#

There are boolean true and false literals:

#if (false)
  This line won't be shown.
#elseif (false || (true && poet))
  This line will be shown.
#end

Scopes:

       Expected
       Actual

       "foo"
       #foo()

    <tr>
      <td>"bar"</td>
      <td>#bar()</td>
    </tr>

    <tr>
      <td>""</td>
      <td>#baz()</td>
    </tr>

    <tr>
      <td>"foo"</td>
      <td>#quux()</td>
    </tr>
  

An inline macro:

#macro print_poet_name (poet_name)
The poet's name is ${poet_name}.
#end

  #print_poet_name (poet.name)

The bracket operator:

${poet["name"]} was born in ${poet["birthdate"]["year"]}.

Some text to be HTML-escaped:

${escHtml(someText)}

Dollar signs can be used unescaped, as long as they're
not followed by '{':

The apples cost $3.00.

It's possible to escape print expressions:

\${poet.name}

With two backslashes, you get:

\\${poet.name}

A dollar sign followed by an expansion:

$${poet.name}

A dollar sign followed by an escape:

$\${poet.name}

You can also escape directives:

  \#if (poet)
    Do something.
  \#end

Escapes in string literals:

#set (b = "\\")
#set (n = "\n")
#set (t = "\t")
#set (q = "\"")

${t}A quotation mark: ${q}${n}${t}And a backslash: ${b}

Nested comments:

#* Here's another comment.

   #* With a nested comment.

      Containing a string: "Hello, world!"

      And a string with comment characters: "*#"
   *#
*#

A string containing comment characters:

  ${"#* This isn't a comment."}

You can write \#else\# and \#end\# to avoid newlines:

The poet's name is #if (poet)${poet.name}#else# This won't be shown#end#.

Some UTF-8 text:

En général, les techniciens sont prêts à répondre uniquement aux questions concernant
les logiciels qu'ils maintiennent.

A footer, included from another file:

#include ("footer.tmpl")

