package mustache

  1. Overview
  2. Docs
Mustache logic-less templates in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

mustache-3.2.0.tbz
sha256=080b6852ce81f2604134348e19d7b1c8d2ea311519be854ad4517729508c4d4c
sha512=80bf68ab0547002290254979cb60ad0962ac526551f9a7a0337c4f0426128b2974ca1d9efbac345613d73b340d7027e1331a0baad0d3743256dbd1b2d97f1eb0

README.md.html

ocaml-mustache

mustache.js logic-less templates in OCaml

Example usage

let tmpl =
  try
    Mustache.of_string "Hello {{name}}\n\
                        Mustache is:\n\
                        {{#qualities}}\
                        * {{name}}\n\
                        {{/qualities}}"
  with Mustache.Parse_error err ->
    Format.eprintf "%a@."
      Mustache.pp_template_parse_error err;
    exit 3

let json =
  `O [ "name", `String "OCaml"
     ; "qualities", `A [ `O ["name", `String "awesome"]
                       ; `O ["name", `String "simple"]
                       ; `O ["name", `String "fun"]
                       ]
     ]

let rendered =
  try Mustache.render tmpl json
  with Mustache.Render_error err ->
    Format.eprintf "%a@."
      Mustache.pp_render_error err;
    exit 2

Supported template language

ocaml-mustache accepts the whole Mustache template language, except:

  • it does not support setting delimiter tags to something else than '{{' and '}}'.

  • it does not support lambdas inside the provided data

It is automatically tested against the latest mustache specification testsuite.

ocaml-mustache also supports template inheritance / partials with parameters, tested against the semi-official specification.

Todo/Wish List

  • Support for ropes

http://mustache.github.io/

OCaml

Innovation. Community. Security.