Filling templates multiple times, à la mail-merge -- maybe a non-use case?
#125
Open
opened 3 years ago by RenaissanceBug
·
3 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?
Is there a way in Pollen (or a Scribble layer reachable from Pollen) to go from [an xexpr template] to [a function that renders the template for a given output-filename and given template inputs]?
For part of my site, I have an xexpr template I'd like to fill in multiple times, rendering each copy to HTML and PDF linked from a main page. The data to populate the template is coming from an Excel sheet, and the file names are derivable from the data. So this is very much like doing an old-fashioned mail-merge, just with data that's too structurally rich for kludging together a solution with fields in a Word doc.
The fact that all the render functions in Pollen work from some form of path makes me think I'm barking up the wrong tree here. I could, say, generate a bunch of .html.pm files that all use the same template...but that feels like a graceless way to do it. So, I'm suspecting Pollen may not be the right tool in the Racket/Scribble ecosystem for what I want, but I also suspect someone in this community will be easily able to point me in a likely right direction if so.
Pollen is designed as a “publishing system for authors”, so if you just want to transform data without an intermediate authoring step then you may not need Pollen.
The most direct way to do what you want in Racket would be to write a function that ingests your spreadsheet data (e.g. using
simple-xlslx
orcsv-reading
) and produces a list of records in whatever intermediate format you want (structs or x-expressions, doesn’t matter). Then write a function that can render a record in that intermediate format into HTML and a function that does the same for PDF (likely via LaTeX or similar). Shameless self-plug, you may find my Beeswax template lang of use for this rendering step.In addition to @otherjoel’s suggestions, an approach I’ve used in similar cases involves turning the “mail merge” fields into Racket parameters. Rather than relying on
raco pollen render ···
, you’d trigger the rendering using a helper script, using a singlemerge.html.pm
file withparameterize
to change the field values on each pass. After each render, change the name of the resultingmerge.html
to whatever you want. Repeat loop until done.Thanks for the replies! I'll play with this some more, but between your two suggestions I should be able to make something work easily enough.