'stem' is a simple templating library for clojure. stem was created to offer a simpler, light weight alternative to template rendering.
'stem' is moving to a new organisation and moving to a 'sane' versioning system. The library now uses sci to render expressions.
[sats/stem "0.1.0-alpha1"]
The previous version of the API is available in the
stem.deprecated.core namespace. Just require this namespace instead
of stem.core. This namespace will be removed in future releases, and
the new API has powerful features.
[satssats/stem "0.1.0-alpha1"]
;; In your namespace:
(ns my.ns
(:require [sats.stem.core :refer :all]))
stem template supports variables and expressions.
Variables in the template must be wrapped within {{ }}. For eg:
{{ name }}. stem substitues variables with values supplied in the
data map.
(render-string "Hello {{ name }}" {:name "sathya"})
; => "Hello sathya"
Expressions must be wrapped within {% %}. Expressions are valid
clojure expression supported by the
sci library. Variables can be used
inside expressions.
(render-string "Hello {% (capitalize {{ name }}) %}"
{:name "sathya"}
:bindings
{'capitalize clojure.string/capitalize})
; => Hello Sathya
(render-string "{% (capitalize {{ name }}) %} lives in {% (get {{ country-names }} {{ country-code }}) %}."
{:user-name :sathya, :country-code :uk :country-names {:uk "United Kingdom"}}
:bindings
{'capitalize clojure.string/capitalize})
; => Sathya lives in United Kingdom
Copyright © 2015-2017 Sathyavijayan Vittal
Distributed under the Apache License v 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
Can you improve this documentation? These fine people already did:
Sathyavijayan Vittal & Sathya VittalEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |