Comments (5)
At one point I thought about having templates for templates but it all got too ridiculous. In my experience most of what you describe is a matter of importing a common header and footer, which is easy enough to do with file->string
, for instance:
;; test.html.pm
#lang pollen
hello world
;; template.html.p
◊(local-require racket/file)
◊(file->string "header.rktd")
◊(->html doc)
;; header.rktd
<h1>Included!</h1>
from pollen-users.
would defining the header as a variable that you insert in every template work? it's not nesting, but…
from pollen-users.
Hmm, I suppose I could define each component of the template separately (possibly as Pollen code) and then each template.html.p
file combines the components I want.
from pollen-users.
One approach I’ve used was to create a separate module, and all the reusable HTML snippets I might want in a template are implemented there as functions. (Example) Then I require
and re-provide
this module from pollen.rkt
so it is available for use inside templates.
My understanding is that the more code you put inside Racket modules as opposed to putting it inside the template itself, the better, because Racket modules can be precompiled and cached while templates are evaluated fresh every time they are used.
Note the use of #lang pollen/mode
to allow using Pollen syntax inside a Racket module (more info in the Pollen docs). This is just a convenience that comes in handy for templatey stuff. Another way of representing HTML snippets as functions is to use scribble/html
, as shown in @soegaard's web-tutorial project (see this file in particular).
from pollen-users.
I ended up addressing this by doing as much as possible with X-expressions in Racket. I have a bunch of snippets which look like:
;; Default code snippets, mostly for inclusion in templates
(define (default-head)
`(head
,@(meta:defaults)
,(head:title)
,@(head:stylesheets "/css/fonts.css" "/css/style.css")))
(define (default-navigation)
`(header ,(navigation "Colophon" "Posts" "Drafts" "Series")))
(define (body-with #:id [id #f]
#:class [cls #f]
#:navigation [nav (default-navigation)]
#:contents contents)
(let ((attrs (match* (id cls)
[ [#f #f] '() ]
[ [id #f] `((id ,id)) ]
[ [#f cls] `((class ,cls)) ]
[ [id cls] `((class ,cls) (id ,id)) ]
)))
`(body ,attrs ,nav ,contents)))
and then I can build templates like so:
<!DOCTYPE html>
<html lang="en">
◊(->html (default-head))
◊(->html (body-with
#:class "theme-dark"
#:contents `(div ((id "content"))
,@(select* 'root doc))))
</html>
from pollen-users.
Related Issues (20)
- render index.ptree with subdirectories changes directory (though not project root) HOT 8
- Is parallel mode known to crash a lot? HOT 1
- decode-elements with decode-paragraphs inserts spurious <p> when nesting lists? HOT 2
- multiple text arguments? HOT 5
- serialising txexprs? HOT 2
- Beautiful Racket Racket docs HOT 1
- Classic tangle/weave support a la org/babel-mode HOT 2
- Add source tag to default block-tags HOT 3
- Importing text from other sources HOT 2
- One source file → multiple outputs of same type? HOT 6
- Having a hard time with maps HOT 4
- Metadata on pagenodes (?) / how to render link traversal HOT 5
- Filling templates multiple times, à la mail-merge -- maybe a non-use case? HOT 3
- Inserting html comment with pollen command HOT 4
- splitf-txexpr: how to use the resulting txexpr HOT 2
- Windows: Set Pollen environment variable HOT 2
- execute shell command via preprocessor?
- Mildy Dynamic Websites
- opinions sought: costs & benefits of switching to self-hosted Git server? HOT 17
- Could not find MANIFEST for package source HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pollen-users.