HTML Macros
Another feature of FOO is that it allows you to define HTML “macros” that can translate arbitrary forms into HTML s-expressions that the html
macro understands. For instance, suppose you frequently find yourself writing pages of this form:
(:html
(:head (:title "Some title"))
(:body
(:h1 "Some title")
... stuff ...))
You could define an HTML macro to capture that pattern like this:
(define-html-macro :standard-page ((&key title) &body body)
`(:html
(:head (:title ,title))
(:body
(:h1 ,title)
,@body)))
Now you can use the “tag” :standard-page
in your s-expression HTML, and it’ll be expanded before being interpreted or compiled. For instance, the following:
(html (:standard-page (:title "Hello") (:p "Hello, world.")))
generates the following HTML:
<html>
<head>
<title>Hello</title>
</head>
<body>
<h1>Hello</h1>
<p>Hello, world.</p>
</body>
</html>
当前内容版权归 gigamonkeys 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 gigamonkeys .