Liking cljdoc? Tell your friends :D

Majavat

A templating engine for Clojure

Installation

Add majavat to dependency list

[org.clojars.jj/majavat "1.0.0"]

Usage

Rendering templates

(: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:

OptionDefault ValueSupported Options
return-type:string:string, :input-stream
content-resolverResourceContentResolverAny ContentResolver implementation

Creating templates

Inserting value

Rendering file with content

Hello {{ name }}!
(render-file "input-file" {:name "world"}) ;; => returns Hello world!

Conditionals

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!"

Looping

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"

Including template

file.txt content

foo

Rendering input file with content:

included {% include "file.txt" %}
(render-file "input-file" {}) ;; returns "included foo"

Extending template

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"

ContentResolver

The ContentResolver protocol provides a uniform interface for accessing template content from different sources.

Protocol Methods

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

Built-in Implementations

  • ResourceContentResolver (default) - Reads from classpath
  • FileSystemContentResolver - Reads from filesystem

License

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 & jj
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close