这是enlive 1.1.5(为清楚起见添加了源格式/空白更改。):
blogen.core> (html/sniptest "<html><head>
<title><span id=\"foo\"/></title>
</head></html>"
[:#foo] (html/substitute "f"))
"<html><head><title></title></head></html>f"
blogen.core> (html/sniptest "<html><head>
<title><span id=\"foo\"/></title>
</head></html>"
[:#foo] (constantly "f"))
"<html><head><title></title></head></html>f"
我想在 HTML 源代码中编写一个常量前缀,这样我的 clojure 代码就不会从我的最终内容中饱和。但正如上面的 sniptest 所示,我不能span在title. 使用核心函数的第二个测试constantly表明,任何更多的自定义编写的转换都不太可能取得更好的成功。
我不想使用,${vars}因为它们在模板中看起来很愚蠢。我更喜欢在模板中编写体面的示例,然后可以在没有损坏的情况下进行替换。
动机
基本上,我会喜欢将模板编写为 HTML 并使用已span定义的元素id作为变量占位符。但是 enlive 不会根据需要解析'sspan内的那些标签。title为了让事情不那么复杂。例子:
<title><span id="article-name"/> - <span id="my-site" /></title>
或者
<p>Welcome, <span id="visitor-ip" /></p>