From 89f6110bc9e7fa1e19562b834a7c1df987bfb7d2 Mon Sep 17 00:00:00 2001 From: Ethan Hackett Date: Fri, 11 Dec 2015 21:36:09 -0500 Subject: [PATCH] Explain "Custom Helpers" in Panini It took me a little while to track down how to add a custom helper and since it's such a powerful aspect to handlebars and panini I thought it deserved a how to in the docs to save others time in tracking down how to use it. --- docs/pages/panini.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/pages/panini.md b/docs/pages/panini.md index b7563f025..b343c49bf 100644 --- a/docs/pages/panini.md +++ b/docs/pages/panini.md @@ -118,7 +118,7 @@ The `../` is added only on pages in a sub-folder, so the CSS can still be proper ## Helpers -Helpers are special functions that manipulate content on the page. In addition to [Handlebars's built-in helpers](http://handlebarsjs.com/builtin_helpers.html), Panini includes a few custom helpers. +Helpers are special functions that manipulate content on the page. In addition to [Handlebars's built-in helpers](http://handlebarsjs.com/builtin_helpers.html), Panini includes a few custom helpers and you can add your own. ### ifpage @@ -171,6 +171,24 @@ Lorem ipsum [dolor sit amet](http://html5zombo.com), consectetur adipisicing eli {{/markdown}} ``` +### Custom Helpers + +If you don't see the right helper, you can write your own. Add a javascript file to 'src/helpers', restart npm, then call it in your templates. + +``` +// Example file src/helpers/bold.js +module.exports = function(options) { + // options.fn(this) = Handelbars content between {{#bold}} HERE {{/bold}} + var bolder = '' + options.fn(this) + ''; + return bolder; +} +``` +Then in your projects call your custom `{{#bold}}` helper + +``` +{{#bold}}ideas{{/bold}} +``` + --- ## Custom Data -- 2.47.2