clojure - 将多个 html 片段文件与 enlive、clojure 结合起来

标签 clojure enlive

我有多个html文件,要合并成一个html文件。那些多个文件就像页眉、页脚等,是多个文件共有的。我正在使用 enlive 的 html-resource 方法。但是,该方法将缺少的 html 标签插入到最终文件中,这是我不想要的。

输出图如下,

({:tag :html, :attrs nil, :content (
 {:tag :head, :attrs nil, :content (
 {:tag :meta, :attrs {:content text/html; charset=utf-8, :http-equiv Content-Type}, :content ()} 
 {:tag :title, :attrs nil, :content (HewaniLife | Changing The Way You Live)} 
 {:tag :link, :attrs {:href styles/main.css, :rel stylesheet, :type text/css}, :content ()} )} 

 {:tag :body, :attrs nil, :content (
 {:tag :html, :attrs nil, :content ({:tag :body, :attrs nil, :content ({:tag :div, :attrs {:id header}, :content (
 {:tag :h1, :attrs nil, :content ({:tag :a, :attrs {:href index.xhtml, :id logo}, :content (
 {:tag :span, :attrs {:class img-replace}, :content (hewaniLife)})})} 

 {:tag :div, :attrs {:id main-nav}, :content (
 {:tag :ul, :attrs nil, :content (
 {:tag :li, :attrs nil, :content ({:tag :a, :attrs {:href login.xhtml, :id btn-login}, :content (
 {:tag :span, :attrs {:class img-replace}, :content (Login)})})} 
 {:tag :li, :attrs nil, :content ({:tag :a, :attrs {:href index.xhtml, :id btn-home}, :content (
 {:tag :span, :attrs {:class img-replace}, :content (Home)})})} 
 {:tag :li, :attrs nil, :content ({:tag :a, :attrs {:href search.xhtml, :id btn-search}, :content (
 {:tag :span, :attrs {:class img-replace}, :content (Search)})})})})} 
 {:type :comment, :data  end of div#main-nav } 
 {:tag :br, :attrs {:class clear-all}, :content nil})} {:type :comment, :data  end of div#header })})})})}

在这里,您可以看到我插入文件时嵌套的 html 标签。

有没有办法插入这些文件..?

任何人都可以使用任何其他方法..?

最佳答案

您应该使用 defsnippet 并指定您感兴趣的部分。 您的所有碎片甚至可以位于一个页面中,而 defsnippet 会提取不同的碎片。

html-snippet 主要用于repl播放

关于clojure - 将多个 html 片段文件与 enlive、clojure 结合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7466957/

相关文章:

java - 无法在类路径中找到 seesaw/core.clj?

Clojure:应用或到列表

clojure - 使用 core.logic 列出唯一的 DAG 父级

clojure - lein repl 在错误的命名空间中启动

java - 类似于 Enlive 的基于选择器的 Java 模板库

html - 如何使用 enlive 的 clone-for 和 HTML 模板来删除虚拟子元素

unit-testing - 为什么我不能使用 midje 来模拟使用弹弓的 throw+ 抛出的函数

clojure - 附加到 Enlive 中的属性

clojure - 在 deftemplate 中绑定(bind)本地 var 以进行激活