2

だから私は次のHTMLを持っていますlogout.html:

<form id="log_out" name="log_out" action="/log_out" method="post">
  <input type="submit"
         value="Log Out!">
  </input>
</form>

enlive ノードとして読み取る関数が必要なようですlogout.html(少なくともノードが必要だと思いますwrapが、実際にはわかりません)。

(html/defsnippet nav "templates/nav.html" [:ul]
      []
      [:ul] (html/append
                  (html/wrap :li (html/SOME-FUNCTION-IDK "templates/logout.html"))))
4

2 に答える 2

2

これが最善の方法かどうかはわかりませんが、のコンテンツをlogout.htmlenlive スニペットとして定義できます。スニペットはテンプレートに似ていますが、ノードを返し、セレクターを指定してファイルの一部を選択的に取得することもできます (以下の例では、セレクターは:#log_outであり、id="log_out" を持つフォーム要素を意味します)。

(html/defsnippet logout-form "templates/logout.html" [:#log_out] 
  [])

次に、次のようなもの:

(html/defsnippet nav "templates/nav.html" [:ul]
  []
  [:ul] (html/append
          ((html/wrap :li) (logout-form))))) ;; untested! ymmv
于 2014-01-28T03:32:03.090 に答える
1

私はそれを機能させるためにオーバーシンクの答えを修正しなければならなくなりました。

(defn extract-body
  "Enlive uses TagSoup to parse HTML. Because it assumes that it's dealing with
   something potentially toxic, and tries to detoxify it, it adds <head> and
   <body> tags around any HTML you give it. So the DOM returned by html-resource
   has these extra tags which end up wrapping the content in the middle of our
   webpage. We need to strip these extra tags out."
  [html]
  (html/at html [#{:html :body}] html/unwrap))

(html/defsnippet logout "templates/logout.html" [html/root] [])

wrap選択した要素を特定のタグでラップする仕組み。したがって、この場合、#log_outが選択され、liタグでラップされます。

(html/defsnippet nav "templates/nav.html" [html/root]
      []
      [:ul] (html/append (extract-body (logout)))
      [:#log_out] (html/wrap :li))

それは間違いなく私が望むほどきれいではありませんが、うまくいきます。

于 2014-01-28T11:24:22.390 に答える