package handlebars-ml
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page
Handlebars templating for OCaml
Install
dune-project
Dependency
Authors
Maintainers
Sources
0.2.0.tar.gz
md5=67f1188f955ff83091c8c91539548d12
sha512=6e0fe9498bbdf2f17a4f2f83ab969e4792971f5c0a08eb77ad39baa3a35448df32eb2573479a6626b5d002bba4cce66685a3f57a88edf685320ecd978e848da7
Description
OCaml port of the Handlebars.js templating engine
README
handlebars-ml
Handlebars templating for OCaml.
Installation
Install with opam
:
opam install handlebars-ml
CLI usage
opam install handlebars-ml
handlebars-ml -d data.json template.hbs
Optionally, pass a partials directory with -p partials_dir
.
Pass the -h
(or --help
) flag to see all options.
handlebars-ml -h
Library usage
Use Yojson
values for passing JSON data as template context.
let () =
let data = Yojson.Safe.from_string {| { "name": "World" } |} in
let template = "Hello, {{name}}!" in
match Handlebars_ml.compile template data with
| Ok result -> print_endline result
| Error err -> prerr_endline ("Error: " ^ err)
Pass get_helper
and get_partial
functions as named arguments to compile
to use custom helpers and partials. Use JSON types for arguments and return values.
let custom_get_helper name =
let shout = function
| [ `String s ] -> Some (`String (String.uppercase_ascii arg))
| _ -> None
in
match name with
| "shout" -> Some shout
| _ -> Handlebars_ml.default_get_helper name
let () =
let data = Yojson.Safe.from_string {| { "name": "World" } |} in
let template = "Hello, {{shout name}}!" in
match Handlebars_ml.compile ~get_helper:custom_get_helper template data with
| Ok result -> print_endline result
| Error err -> prerr_endline ("Error: " ^ err)
handlebars-ml
provides a default_get_helper
function in Handlebars_ml
that can be used in your custom implementation to still keep the default helpers.
License
MIT
Dependencies (4)
- ppx_deriving
-
yojson
>= "2.0"
-
ocaml
>= "4.14"
-
dune
>= "3.18"
Dev Dependencies (2)
-
odoc
with-doc
-
ppx_inline_test
with-test
Used by
None
Conflicts
None
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page