Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

clojure templating by handlebars.java

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 dev-resources
Octocat-spinner-32 doc
Octocat-spinner-32 java
Octocat-spinner-32 src
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.md
Octocat-spinner-32 project.clj
README.md

hbs

Real-world Clojure templating, seriously. Don't talk about enlive or hiccup on a clojure web development book any more.

Based on handlebars.java

Usage

Leiningen

[hbs "0.5.0"]

Using hbs.core

(use '[hbs.core])

;; render something from template string
(render "foo {{foo}}" {:foo "bar"})

;; configure where to load template file:
(set-template-path! "templates" ".html")

;; render something from templates/index.html
(render-file "index" {:foo "bar"})

Extending hbs.helper

Handlebars is nothing without helpers.

(use '[hbs core helper])

(defhelper mytag [ctx options]
  (safe-str "HelloWorld, " (clojure.string/upper ctx)))

(render "{{mytag foo}}" {:foo "bar"})

Helpers defined by me

I have some predefined helpers used in my projects. And I decide to ship it in the release.

To use these helpers, be sure eval hbs.ext. You can just add a (:require [hbs.ext]) on you core namespace.

Available helpers:

  • ifequals
  • ifgreater
  • ifless
  • ifcontains
  • uppercase
  • lowercase
  • or
  • count
  • format-date
  • format
  • ifempty
  • max
  • min

License

Copyright © 2013 Sun Ning

Distributed under the Eclipse Public License, the same as Clojure.

Something went wrong with that request. Please try again.