A templating engine for Clojure
Add majavat to dependency list
[org.clojars.jj/majavat "1.0.0"]
(:require
[jj.majavat :as majavat])
(majavat/render-file "index.html" {:user "jj"})
Additional options can be passed with
(majavat/render-file "index.html" {:user "jj"} {:return-type :input-stream})
All supported options:
Option | Default Value | Supported Options |
---|---|---|
return-type | :string | :string , :input-stream |
content-resolver | ResourceContentResolver | Any ContentResolver implementation |
Rendering file with content
Hello {{ name }}!
(render-file "input-file" {:name "world"}) ;; => returns Hello world!
Rendering input file with content:
"Hello {% if name %}{{name}}{% else %}world{% endif %}!"
(render-file "input-file" {:name "jj"}) ;; returns "Hello jj!"
(render-file "input-file" {}) ;; returns "Hello world!"
Rendering input file with content:
{% for item in items %}
- {{ item }}
{% endfor %}
(render-file "input-file" {:items ["Apple" "Banana" "Orange"]}) ;; returns "-Apple\n- Banana\n- Orange"
file.txt content
foo
Rendering input file with content:
included {% include "file.txt" %}
(render-file "input-file" {}) ;; returns "included foo"
file.txt content
foo
{% block content %}
baz
Rendering input file with content:
{% extends content "file.txt" %}
bar
(render-file "input-file" {}) ;; returns "foo\nbar\nbaz"
The ContentResolver
protocol provides a uniform interface for accessing template content from different sources.
resolve-path
Resolve a relative path against a base path.
(resolve-path resolver "/base/path" "../file.txt")
;; => "/file.txt"
(resolve-path resolver "/base/path" "./sub/file.txt")
;; => "/base/sub/file.txt"
read-content
Read content from a path. Returns the content as a string, or nil
if not found.
(read-content resolver "/templates/header.html")
;; => "<header>Welcome</header>"
content-exists?
Check if content exists at a path.
(content-exists? resolver "/templates/footer.html")
;; => true
Copyright © 2025 ruroru
This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/.
This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.
Can you improve this documentation? These fine people already did:
ruroru & jjEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close