Inserting X-expressions into templates
#48
Closed
opened 9 years ago by basus
·
2 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
I'm trying to build a blog-like system on top of Pollen. I've been putting properties like creation and modification date into the
'meta
. At a point in the template I have code which looks like:The
mk-date
function is defined in mydirectory-require.rkt
as:However, it looks like the output of
mk-date
is not processed as an X-expression. What I see in the HTML is:<p>Originally published: pSunday, April 19th, 2015</p>
.Admittedly, the
mk-date
function is a bit overkill for this particular application, but I'll probably want to do similar things, where some user-specified fields in'metas
are processed into more complicated structures before getting injected into a template.I just realized that changing the template line to be
makes things work fine. Should I consider this is the default/best way to handle this kind of thing.
Right. Anytime you want to put an X-expression into a template (HTML or otherwise), you need to explicitly specify the conversion function. For HTML templates, usually
->html
is the solution. This is true of the maindoc
export, but also any other X-expressions you add to the template.Your solution will work, though the HTML will end up looking like this:
The
->html
function has a#:splice
option that will discard the surrounding tag, so this:Gets you this:
For date and time manipulations, I recommend
gregor
.