Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

Edit Template

liquidz edited this page Apr 11, 2012 · 7 revisions

Template file

Template files are compiled with hiccup.

Example

;; Define template options here
; @layout  default
; @title   misaki

;; definition your clojure function
(defn header [s] [:header [:h1 s]])

;; "site" variable to access template options
(header (:title site))

[:h2 "Posts"]
[:ul
 (for [p (:posts site)]
   [:li (:title p)])]

Template options

Template option format:

; @key value

Special options

  • layout: Specify layout file.
  • title: Define template title.
  • format: Specify template format ("html5", "xhtml" and "html4"). No format template will be compiled by hiccup.core/html.

Access template options

misaki provides site variable to acess defined template options. For example, you can access template title with (:title site).

Site updated date

(:date site) is site updated date (org.joda.time.DateTime).

Functions

You can define functions in templare or layout. However, special variable(e.g., site and contents) is not accessible in those functions.

Posts

(:posts site) is post data list.

Post data format

  • :title: Post title.
  • :url: Post URL.
  • :date: Post date (org.joda.time.DateTime).
  • :file: Post file (java.io.File).
  • :tag: Tag list for this post.
  • :lazy-content: Delayed post content. Use force to get post content.

Tag list format

  • :name: Tag name.
  • :url: Tag page URL.

Post tags

(:tags site) is all post's tag data list.

Tag data format

  • :name: Tag name.
  • :url: Tag page URL.
  • :count: Tag counts.

Code Highlight

Codes are highlighted by google-code-prettify.

#-CODE
(println "hello")
CODE

CODE can be replaced by any string.

If you define highlight setting, CODE string specifies a language. To define highlight setting, see Highlight Setting.


Layout file

Example

Layout options is same as template options.

; @title  default title
; @format html5

[:head
 [:title (:title site)]]
[:body contents]

Special variable

  • site: Variable to access layout options.
  • contents: Variable to handle template contents.

Layout in layout

Layout file can contain :layout option.

  • default.clj
; @title default title
; @format html5
[:head [:title (:title site)]]
[:body contents]
  • post.clj
; @layout default
; @title post default title
[:h1 (:title site)]
contents

Tag layout

Tag layout which is defined as :tag-layout in _config.clj has special site keyword.

  • (:tag-name site): Tag name.
  • (:posts site): Post list which contains this tag.

Back to Home