common-lisp - 如何将列表传递给 cl-mustache?

标签 common-lisp mustache

我正在尝试使用CL-MUSTACHE 。按照 README 中的示例,渲染原子变量工作正常。文件:

> (mustache:mustache-render-to-string "{{year}}-{{month}}-{{day}}" 
                                      '((:year . "2012")
                                        (:month . "07")
                                        (:day . "02")))
"2012-07-02"

但是,我无法弄清楚如何传递列表来多次渲染一个部分。 README文件没有示例,我尝试过的方法不起作用。例如:

(mustache:mustache-render-to-string "{{#dates}}{{year}}-{{month}}-{{day}}
{{/dates}}" 
                                    '((:dates . (((:year . "2012")
                                                  (:month . "07")
                                                  (:day . "02"))
                                                 ((:year . "2013")
                                                  (:month . "08")
                                                  (:day . "03"))))))
"--
"

最佳答案

我没有它来检查,但从文档来看,数组似乎被视为 CL 数组,所以你可以尝试这个看看它是否有效:

(mustache:mustache-render-to-string "{{#dates}}{{year}}-{{month}}-{{day}}{{/dates}}" 
                                    '((:dates . #( ((:year . "2012")
                                                    (:month . "07")
                                                    (:day . "02"))
                                                   ((:year . "2013")
                                                    (:month . "08")
                                                    (:day . "03"))))))

(即参数列表的数组)。

关于common-lisp - 如何将列表传递给 cl-mustache?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11301654/

相关文章:

lisp - 为什么(列表类型)等于 CONS?

lisp - 如何通过知道其在 lisp 中的位置来查找列表元素?

javascript - Mustache js 导致无法加载资源错误

javascript - 将 mustache.js 部分与 express 结合使用

javascript - Django 模板中的 Mustache.js 不起作用

function - Common Lisp 中的 FUNCALL 和 #'function-name 有什么区别?

list - 如何将文件中的列表添加到 Lisp

LISP 使用负数作为指数

html - 使用 Mustache 在 HTML 中添加 css 类列表

javascript - 使用 Mustache js 更新模板