diff --git a/src/selmer/filter_parser.clj b/src/selmer/filter_parser.clj index 0e9ecfc..b1b5383 100644 --- a/src/selmer/filter_parser.clj +++ b/src/selmer/filter_parser.clj @@ -134,7 +134,7 @@ applied filter." val (map vector filter-strs filters))) -(defn- get-accessor [m k] +(defn get-accessor [m k] "Returns the value of `k` from map `m`, either as a keyword or string lookup." (or (get m k) (when (keyword? k) diff --git a/src/selmer/tags.clj b/src/selmer/tags.clj index ed948a4..6f9916b 100644 --- a/src/selmer/tags.clj +++ b/src/selmer/tags.clj @@ -1,6 +1,6 @@ (ns selmer.tags (:require selmer.node - [selmer.filter-parser :refer [split-filter-val safe-filter compile-filter-body fix-accessor]] + [selmer.filter-parser :refer [split-filter-val safe-filter compile-filter-body fix-accessor get-accessor]] [selmer.filters :refer [filters]] [selmer.util :refer :all] [json-html.core :refer [edn->html]]) @@ -44,7 +44,7 @@ item-keys (parse-arg items)] (fn [context-map] (let [buf (StringBuilder.) - items (-> (get-in context-map item-keys) + items (-> (reduce get-accessor context-map item-keys) (apply-filters filters context-map items)) length (count items)] (if (and empty-content (empty? items)) diff --git a/test/selmer/core_test.clj b/test/selmer/core_test.clj index a5dfbd2..2bbba18 100644 --- a/test/selmer/core_test.clj +++ b/test/selmer/core_test.clj @@ -252,7 +252,11 @@ "<<1>><<2>><<3>>")) (is (= (render "{% for ele in foo %}{{ele}}-{{forloop.counter}}-{{forloop.counter0}}-{{forloop.revcounter}}-{{forloop.revcounter0}};{%endfor%}" {:foo [1 2 3]}) - "1-1-0-2-3;2-2-1-1-2;3-3-2-0-1;"))) + "1-1-0-2-3;2-2-1-1-2;3-3-2-0-1;")) + (is (= (render "{% for ele in foo %}{{ele.bar}} {% endfor %}" + {"foo" [{:bar "bar"} + {:bar "bar"}]}) + "bar bar "))) (deftest for-filter-test (is