cl-who 中的格式无法正常工作
我正在尝试通过 hunchentoot 和 cl-who 构建一个个人网站,但在以下代码中出现语义错误:
(defun index ()
(standart-page (:title "~apb")
(dolist (article (articles))
(cl-who:htm
(:ul
(:li (format nil "~a: ~a" (article-date article) (article-title article))))))))
“standart-page”是一个宏:
(defmacro standart-page ((&key title) &body body) `(cl-who:with-html-output-to-string (*standart-output* nil :prologue t :indent t)
(:html :xmlns "http://www.w3.org/1999/xhtml"
:xml\:lang "de"
:lang "de"
(:head
(:title ,title)
(:body
(:div :id "wrapper"
(:div :id "header"
(:h1 "~apb"))
(:div :id "content"
,@body)))))))
“(index)”的评估(通过一个测试“(articles)”中的文章返回:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='de' lang='de'>
<head>
<title>
~apb
</title>
<body>
<div id='wrapper'>
<div id='header'>
<h1>
~apb
</h1>
</div>
<div id='content'>
<ul>
<li>
</li>
</ul>
</div>
</div>
</body>
</head>
</html>
通过查看
标签,我想知道为什么没有输出,我认为格式函数有问题。但我不明白是什么。
I'm trying to build a personal Website via hunchentoot and cl-who, but I'm occurring an semantic error in the following code:
(defun index ()
(standart-page (:title "~apb")
(dolist (article (articles))
(cl-who:htm
(:ul
(:li (format nil "~a: ~a" (article-date article) (article-title article))))))))
"standart-page" is a macro:
(defmacro standart-page ((&key title) &body body) `(cl-who:with-html-output-to-string (*standart-output* nil :prologue t :indent t)
(:html :xmlns "http://www.w3.org/1999/xhtml"
:xml\:lang "de"
:lang "de"
(:head
(:title ,title)
(:body
(:div :id "wrapper"
(:div :id "header"
(:h1 "~apb"))
(:div :id "content"
,@body)))))))
The evaluation of "(index)" (with one test article in "(articles)" returns:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='de' lang='de'>
<head>
<title>
~apb
</title>
<body>
<div id='wrapper'>
<div id='header'>
<h1>
~apb
</h1>
</div>
<div id='content'>
<ul>
<li>
</li>
</ul>
</div>
</div>
</body>
</head>
</html>
By looking at the <li>..</li>
tags I was wondering why there is no output. I think there's something wrong with the format function but I cant't figure out what.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
具体来说,对于
格式
,安德鲁的答案是正确的。一般来说,您可以使用str
:请注意,在这种情况下,字符串不是 HTML 转义的(这也适用于
fmt
)。如果您希望这样,请使用esc
代替:同样,在退出 HTML 模式后,使用
htm
返回 HTML 模式:For
format
specifically, Andrew's answer is the right one. In general, you can usestr
:Note that the string isn't HTML-escaped in this case (this goes for
fmt
as well). If you want it to be, useesc
instead:Similarly, use
htm
to get back into HTML mode when having escaped out of it:一个明显的错误是你拼错了“标准”。因此,将流绑定到 *standard-output* (原文如此)不会重新绑定
*standard-output*
,正如您可能想要的那样。One obvious mistake is that you misspelt "standard". Therefore, binding a stream to
*standart-output*
(sic) does not re-bind*standard-output*
, as you perhaps intended.查看 CL-WHO 网站上的使用示例,我认为您不能只执行返回字符串的格式。他们的所有示例都使用自定义输出函数(例如 fmt),这些函数似乎在后台写入动态变量。在 CL-WHO 生成的代码示例中,您可以将其视为宏扩展中的
(format http-output-stream ....)
行。这可以解释为什么您没有得到任何输出,您只需要使用他们的自定义输出编写器而不是您正在使用的
(format nil ..)
。你可能想要类似的东西
(fmt "~a: ~a" (文章-日期文章) (文章-标题文章))
Looking at the examples of usage on the CL-WHO site I don't think you can just do a format that returns a string. All of their examples either use custom output functions (for example fmt) that appear to write to a dynamic variable under the hood. In the example of code generated by CL-WHO you see this as a
(format http-output-stream ....)
line in the macro expansion.This would explain why you're not getting any output, you just need to use their custom output writers instead of the
(format nil ..)
that you're using. You probably want something like(fmt "~a: ~a" (article-date article) (article-title article))