About this book

This book contains every handlebars features and example, you can find working example code for both handlebars.js and lightncandy

What is...


Mustache is a logic-less template syntax. It can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object.


Handlebars.js is an extension to the Mustache templating language created by Chris Wanstrath.


LightnCandy is an extremely fast PHP implementation of handlebars and mustache.

How mustache/handlebars works...


My name is {{name}} and I am {{age}} years old.

+ data

  "name": "John",
  "age": 18

= result

My name is John and I am 18 years old.

Keyboard Shortcuts

You may use keyboard to navigate this book fast:

When the drop down menu is displayed, you can:





Sample output


Different output


Error output

Partials List

partial_namepartial template
partial_name2partial template...


Option1 Option2


Table of Content

  1. About this book
  2. Create your project
  3. Hello World
  4. Simple Variable
  5. Variable Escaping
  6. Raw Output
  7. Specific Values
  8. Block
  9. Inverted Block
  10. Comment
  11. Partials
  12. Set Delimiter
  13. Dot Notation
  14. Handlebars: Path
  15. Handlebars: Extended Comment
  16. Handlebars: Built-in block helper - #if
  17. Handlebars: Built-in block helper - #unless
  18. Handlebars: Built-in block helper - #with
  19. Handlebars: Built-in block helper - #each
  20. Handlebars: Built-in helper - lookup
  21. Handlebars: Custom Helper
  22. Handlebars: Block Custom Helper
  23. Handlebars: Named Arguments
  24. Handlebars: Change Partial Context
  25. Handlebars: Parent Context
  26. Handlebars: Subexpression
  27. Handlebars: Advanced Variable
  28. Handlebars: Dynamic Partial
  29. Handlebars: Use SafeString
  30. Handlebars: Change Context
  31. Handlebars: Whitespace Control
  32. Handlebars: Partial Block
  33. LightnCandy: Quick Start
  34. LightnCandy: Custom Helper
  35. LightnCandy: The $options Object
  36. LightnCandy: Use SafeString
  37. LightnCandy: Deep Dive Partials
  38. LightnCandy options
  39. LightnCandy option: helperresolver
  40. LightnCandy option: partialresolver
  41. LightnCandy option: safestring
  42. LightnCandy option: FLAG_ADVARNAME
  43. LightnCandy option: FLAG_BESTPERFORMANCE
  44. LightnCandy option: FLAG_ECHO
  45. LightnCandy option: FLAG_ELSE
  46. LightnCandy option: FLAG_ERROR_EXCEPTION
  47. LightnCandy option: FLAG_ERROR_LOG
  48. LightnCandy option: FLAG_ERROR_SKIPPARTIAL
  49. LightnCandy option: FLAG_EXTHELPER
  50. LightnCandy option: FLAG_HBESCAPE
  51. LightnCandy option: FLAG_INSTANCE
  52. LightnCandy option: FLAG_JS
  53. LightnCandy option: FLAG_JSLENGTH
  54. LightnCandy option: FLAG_JSOBJECT
  55. LightnCandy option: FLAG_JSTRUE
  56. LightnCandy option: FLAG_METHOD
  57. LightnCandy option: FLAG_NAMEDARG
  58. LightnCandy option: FLAG_NOESCAPE
  59. LightnCandy option: FLAG_PARENT
  60. LightnCandy option: FLAG_PARTIALNEWCONTEXT
  61. LightnCandy option: FLAG_PROPERTY
  62. LightnCandy option: FLAG_RENDER_DEBUG
  63. LightnCandy option: FLAG_RUNTIMEPARTIAL
  64. LightnCandy option: FLAG_SLASH
  65. LightnCandy option: FLAG_STANDALONEPHP
  66. LightnCandy option: FLAG_THIS