On Mar 15, 2018, at 6:00 AM, Joel Dueck <dueck...@gmail.com> wrote:I was pretty happy to learn about the web-server/templates package, which allows you to include the contents of a template file and have it dropped into the lexical context of the calling site. I’ve often wanted something like this so I could write only a single copy of things like headers and footers, and partials for listing chapters/articles in different contexts, etc.
I started fiddling with it in a Pollen project and, come to realize it was working even though I hadn’t `require`d or `provide`d any functions from web-server/template. How is this possible, I think. Some digging revealed that Pollen implements its own `include-template` function—and that it is provided automatically for code inside a Pollen template.
- have you thought about including it in the docs? It’s pretty useful, and the docs could also help avoid confusion among those who already know about web-server/template. The docs do mention that include-template is used behind the scenes but not that it's also available in Pollen templates. With appropriate warnings about XSS concerns.
- might it also be worth providing or reimplementing web-server/template's `in` function? [2] (maybe it already does so, I confess I haven’t checked yet) And then, perhaps including it in the docs somewhere as well.
Pollen templates can do all this too, for a not-very-surprising reason (keep reading) ...The `include-template` in Pollen is the same one as in `web-server/templates`
[...] I've just never been clear what could be done with `include-template` directly that isn't already possible through existing Pollen functions. When you apply a template to a markup source during a render, you're already using `include-template`.
In fine, what interests me is smaller templates reusable within multiple "main" templates, the ones that Pollen grabs and applies to the markup source. And I like that Pollen gives me include-template as an option for doing this.
- might it also be worth providing or reimplementing web-server/template's `in` function? [2] (maybe it already does so, I confess I haven’t checked yet) And then, perhaps including it in the docs somewhere as well.
Same — I suppose I've always thought that because Pollen has a notion of X-expressions and tag functions, they subsume `in` (which, unlike `include-template`, does no heavy lifting anyhow)
<table> |
@for/list[([c clients])]{ |
@list{ |
<tr><td>@(car c), @(cdr c)</td></tr> |
} |
} |
</table> |
<table> |
@in[c clients]{ |
<tr><td>@(car c), @(cdr c)</td></tr> |
} |
</table> |
On Mar 15, 2018, at 11:49 AM, Joel Dueck <dueck...@gmail.com> wrote:In fine, what interests me is smaller templates reusable within multiple "main" templates, the ones that Pollen grabs and applies to the markup source. And I like that Pollen gives me include-template as an option for doing this.
The case `in` makes for itself [1] is that it shortens a template like this:
I see what you mean, though wouldn't `file->string` suffice? Here, we turn the main template into a `pp` file so the Pollen commands therein get executed.
At an earlier stage in Pollen's life I implemented a special template dialect that would allow templates to have templates. [..] It would've used a different command character so the two rounds of Pollen commands would stay distinct.
The case `in` makes for itself [1] is that it shortens a template like this:Could you post a full working example as a gist or equiv so I can fiddle with it?
On Mar 16, 2018, at 2:30 PM, Joel Dueck <dueck...@gmail.com> wrote:At an earlier stage in Pollen's life I implemented a special template dialect that would allow templates to have templates. [..] It would've used a different command character so the two rounds of Pollen commands would stay distinct.
That's interesting, but the need to think in terms of "rounds of Pollen commands" is not clear to me. Whether using `include-template` or `file->string`, there is only one "round": the sub-template gets lifted into the current context and then evaluated right alongside everything else. Maybe I'm oversimplifying it though?
The case `in` makes for itself [1] is that it shortens a template like this:Could you post a full working example as a gist or equiv so I can fiddle with it?
Sure, here it is: https://gist.github.com/otherjoel/cde1aef9b582392efcdb12d74d65bf7c
Predictably, GitHub doesn't allow me to change the name of the gist or the ordering of files, so the least relevant files are at the begin