【问题标题】:combine multiple html fragment files with enlive, clojure将多个html片段文件与enlive、clojure结合起来
【发布时间】:2011-10-07 18:49:01
【问题描述】:

我有多个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标签。

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

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

【问题讨论】:

    标签: clojure enlive


    【解决方案1】:

    您应该改用defsnippet 并指定您感兴趣的部分。 您的所有片段甚至可以驻留在一个页面中,而 defsn-p 会提取不同的片段。

    html-snippet主要用于repl玩

    【讨论】:

      【解决方案2】:

      我在enlive 中找到了一个名为html-snippet 的方法。您可以使用它来组合多个html片段代码。

      【讨论】:

        猜你喜欢
        • 2014-12-02
        • 2019-08-15
        • 2023-03-09
        • 2018-07-11
        • 1970-01-01
        • 2021-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多