14.7 Template
(require pollen/template) | package: pollen |
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.
procedure
(->html xexpr-or-xexprs [ #:tag html-tag #:attrs html-attrs #:splice splice-html?]) → string? xexpr-or-xexprs : (or/c xexpr? (listof xexpr?)) html-tag : (or/c #f txexpr-tag?) = #f html-attrs : (or/c #f txexpr-attrs?) = #f splice-html? : boolean? = #f
Examples: | |||||||
|
The optional keyword arguments html-tag and html-attrs let you set the outer tag and attributes for the generated HTML. If xexpr-or-xexprs already has an outer tag or attributes, they will be replaced.
Examples: | |||||||||||
|
Whereas if xexpr-or-xexprs has no tag or attributes, they will be added. If you supply attributes without a tag, you’ll get an error.
Examples: | ||||||||||||||
|
If the generated HTML has an outer tag, the splice-html? option will strip it off. Otherwise this option has no effect.
Examples: | ||||||||||||||||||
|
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: | |||||||
|
As the input contract suggests, this function can take either a single xexpr? or a list of xexpr?, with the expected results.
Examples: | ||||||||||||
|
procedure
key : symbolish? value-source : (or/c hash? txexpr? pagenode? pathish?)
procedure
key : symbolish? value-source : (or/c hash? txexpr? pagenode? pathish?)
With select, you get the first result; with select*, you get them all.
In both cases, you get #f if there are no matches.
Note that if value-source is a relative path or pagenode, it is treated as being relative to world:current-project-root. If that’s not what you want, you’ll need to convert it explicitly to a complete-path (e.g., with path->complete-path or ->complete-path).
Examples: | ||||||||||||||||||||
|
procedure
(select-from-metas key meta-source) → (or/c #f xexpr?)
key : symbolish? meta-source : (or/c hash? pagenodeish? pathish?)
Note that if meta-source is a relative path or pagenode, it is treated as being relative to world:current-project-root. If that’s not what you want, you’ll need to convert it explicitly to a complete-path (e.g., with path->complete-path or ->complete-path).
Examples: | |||||||||
|
procedure
(select-from-doc key doc-source) → (or/c #f (listof xexpr?))
key : symbolish? doc-source : (or/c txexpr? pagenodeish? pathish?)
Note that if doc-source is a relative path or pagenode, it is treated as being relative to world:current-project-root. If that’s not what you want, you’ll need to convert it explicitly to a complete-path (e.g., with path->complete-path or ->complete-path).
Examples: | ||||||||||||||||
|
procedure
(when/block condition text-to-insert) → string?
condition : any/c text-to-insert : any/c
◊when/block[condition]{The text to insert.} |
The inserted text can contain its own nested Pollen commands.