Easy Clojure library for simple string templating?

I am looking for a (preferably small) Clojure library, which is available in clojars, which allows me to replace simple patterns in strings, such as:

"Hello, my name is $ {name}"

where it ${name}should be replaced by a template engine. In Java, I usually use JMTE, which works great. I know that maybe I can use it in Clojure too, but I wonder if there is anything more friendly / idiomatic for Clojure.

+5
source share
3 answers

There are quite a few tepmplating libraries. Some common goals may be:

. - , clojure.pprint cl-format. clojure.core/format, java.util.Formatter.

+8

.

, , .

+2

<< core.incubator .

, [org.clojure/core.incubator "0.1.4"] project.clj. (: core.incubator GitHub .)

:

(ns example
  (:require [clojure.core.strint :refer [<<]]))

(def my-name "John")
(<< "My name is ~{my-name}.")
; Returns: "My name is John."

(let [x 3
      y 4]
  (<< "~{x} plus ~{y} equals ~(+ x y)."))
; Returns: "3 plus 4 equals 7."

{} ().

0

All Articles