The newest update to Pollen includes a `current-metas` parameter that makes
this kind of operation simpler. The parameter contains the metas of the source
file currently being evaluated or rendered. So you can avoid using macros, and
write `desc` like so:
#lang racket/base
(require pollen/core)
(provide (all-defined-out))
(define (desc)
(or (and (current-metas) (select-from-metas 'desc (current-metas)))
"My website description"))
> On Feb 15, 2018, at 2:49 PM, Shrutarshi Basu <[email protected]> wrote:
>
> I’m trying to define some macros to help with writing templates. Basically, I
> want to look at a document’s metas and then fill in a default if there is a
> missing meta key.
>
> So in pollen.rkt I have the following:
>
> (define-syntax-rule (with-default call default)
> (let ([tmp call])
> (if tmp tmp default)))
>
> (define (get-description metas)
> (with-default (select-from-metas 'description metas)
> “My Wesbsite description"))
>
> (define-syntax-rule (desc) (get-description (syntax->datum #'metas)))
>
>
> And inside my template.html.p I have
>
> <meta name="description" content="◊(desc)">
>
> I used the syntax->datum part because I know that metas won’t be available in
> pollen.rkt, so I need to splice it in when the macro is expanded in the
> template. However, I get the following error:
>
--
You received this message because you are subscribed to the Google Groups
"Pollen" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.