6.0.1.6
8.6 Template
Convenience functions for templates. These are automatically imported into the eval environment when rendering with a template (see render).
This module also provides everything from sugar/coerce/value.
Convert
xexpr to an HTML string. Similar to
xexpr->string, but consistent with the HTML spec, text that appears within
script or
style blocks will not be escaped.
Examples: |
> (define tx '(root (script "3 > 2") "Why is 3 > 2?")) | | > (xexpr->string tx) | "<root><script>3 > 2</script>Why is 3 > 2?</root>" | > (->html tx) | "<root><script>3 > 2</script>Why is 3 > 2?</root>" |
|
Be careful not to pass existing HTML strings into this function, because the angle brackets will be escaped. Fine if that’s what you want, but you probably don’t.
Examples: |
> (define tx '(p "You did" (em "what?"))) | | > (->html tx) | "<p>You did<em>what?</em></p>" | > (->html (->html tx)) | "<p>You did<em>what?</em></p>" |
|
Find matches for key in value-source, first by looking in its metas (using select-from-metas) and then by looking in its doc (using select-from-doc). With select, you get the first result; with select*, you get them all. In both cases, you get #f if there are no matches.
Look up the value of
key in
meta-source. The
meta-source argument can be either a set of metas (i.e., a
hash) or a
pagenode?, from which metas are pulled. If no value exists for
key, you get
#f.
Examples: |
> (module ice-cream pollen/markup | '(div (question "Flavor?") | (answer "Chocolate chip") (answer "Maple walnut")) | '(meta ((template "sub.xml.pt"))) | '(meta ((target "print")))) |
| | ; Import doc & metas from 'ice-cream submodule | > (require 'ice-cream) | | > (select-from-metas 'template metas) | "sub.xml.pt" | > ('target . select-from-metas . metas) | "print" | > (select-from-metas 'nonexistent-key metas) | #f |
|
Look up the value of
key in
doc-source. The
doc-source argument can be either be a
doc (i.e., a
txexpr) or a
pagenode?, from which doc is pulled. If no value exists for
key, you get
#f.
Examples: |
> (module gelato pollen/markup | '(div (question "Flavor?") | (answer "Nocciola") (answer "Pistachio")) | '(meta ((template "sub.xml.pt"))) | '(meta ((target "print")))) |
| | ; Import doc & metas from 'gelato submodule | > (require 'gelato) | | > (select-from-doc 'question doc) | '("Flavor?") | > ('answer . select-from-doc . doc) | '("Nocciola" "Pistachio") | > (select-from-doc 'nonexistent-key doc) | #f |
|