我想在 selmer 中迭代一个地图,这样我就可以打印键和值。据我所知,这是不支持开箱即用的,所以我尝试了以下方法:
(defn mapper-tag [args context-map content]
(when-let [map-data (get context-map (keyword (first args))
(get context-map (first args)))]
(apply str (for [[k v] map-data]
(selmer.parser/render (get-in content [:mapper :content]) {:key k :val v})))))
(selmer.parser/add-tag! :mapper mapper-tag :endmapper)
(selmer.parser/render "{% mapper m %}KEY {{key}} \n{% endmapper %}" {:m {:a 1 :b 1}})
我希望这会输出类似
KEY a
KEY b
但它输出
KEY
KEY
任何指针?