On Thursday, March 15, 2018 at 10:11:25 AM UTC-5, Matthew Butterick wrote:
>
>
> 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`
>
>
Yes. That was the realization I had come to in my first post. I just didn't 
know it before (it = "Pollen templates can do all this too") because 
`include-template` is not listed in the Pollen docs as being available to 
template contents.
 

> [...] 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`.
>

So (just to be clear) here's the kind of thing I'm interested in doing:

;; template.html.p
<html>
    ◊include-template["templates/head.html"]
<body>
<h1>Chapters</h1>

◊in[chapter (children here)]{
  ◊include-template["templates/chapter-title-excerpt.html"]
}

;;;;;;;;;;;;;templates/head.html
<head>
   <title>@(select-from-metas 'title here)</title>
   <link rel="stylesheet" href="/style.css">
   [lots of fiddly javascript, favicons, etc]
</head>

;;;;;;;;;;;;;;templates/chapter-title-excerpt.html
<article>
 <h1>@(select-from-metas 'title chapter)
 <p>@(->html (select-from-doc 'excerpt chapter))</p>
  [...]
</article>


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.

Yes, I could just add a set of "HTML template" helper functions to 
pollen.rkt (and then maybe a set of "Latex template" helper functions, 
etc). But:

- I like not having to pass arguments between a template and its helper 
functions. The "sub-template" just knows everything that it's parent 
template knows.
- I like editing these as snippets of HTML more than as functions in a 
module
- I like that reusable template stuff can be separated from all my tag 
functions while still being automatically available in the templates 
themselves.

I freely concede that all this is sugar for my subjective biases. And 
fortunately for me, it's already implemented so I don’t have to make an 
argument for its inclusion. I just thought more people would like to know 
about it.

Also, even though they're subjective, these preferences above seem at least 
akin to those that must have led to Pollen having any "templates", period, 
no?

>
>    - 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)
>

Well, within a doc (tag functions, etc), no, I don't see that I would use 
`in`. It's mainly just shorthand for use in templates, i.e. places where 
you're outside a doc context and want a quick way to glue a fairly static, 
reusable chunk of HTML (or LaTeX or whatever) together.

The case `in` makes for itself [1] is that it shortens a template like this:

  <table>

   @for/list[([c clients])]{

    @list{

     <tr><td>@(car c), @(cdr c)</td></tr>

    }

   }

  </table>

To this:

  <table>

   @in[c clients]{

    <tr><td>@(car c), @(cdr c)</td></tr>

   }

  </table>

Which, hey, I might use that. And I could do `(require (only-in 
web-server/templates in))` to get it (to avoid a collision with 
`include-template` (maybe unnecessary?)). But since Pollen already gives me 
include-template, why not that one too? Although I can see possible 
arguments against this one.

[1]: 
http://docs.racket-lang.org/web-server/templates.html?q=in#%28part._.Gotchas%29

-- 
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 pollenpub+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to