Helpers

CopperSmith includes various handlebars helpers that can be used throughout your template.

is

titleCase

asset

snippet

config

option

has

skin


is

Provides an extended conditional (if) helper.

Usage:

{{#is 'left' 'operator' 'right'}}
_Do Something_
{{/is}}

Available Operators:

  • '==', '==='
  • '!=', '!=='
  • '<'
  • '<='
  • '>'
  • '>='
  • '&&'
  • '||'
Example:
{{#is 'this' '===' 'this'}}
<p>Yes it is</p>
{{/is}}

titleCase

Returns a “Title Cased” version of the provided string.

Usage:

{{titleCase 'some text'}}
Example:
<p>{{titleCase 'some text'}}</p>

will result in

<p>Some Text</p>

asset

Used to return the correct url to an asset, relative to the assets folder, such as a style sheet (.css).

Usage:

{{asset 'css/asset.css'}}
Example:
<link type="text/css" rel="stylesheet" href="{{asset 'css/app.css'}}">

snippet

Used to insert the contents of a snippet file inside a page’s markdown.

Usage:

{{{snippet 'example'}}}
Example:
## Example Markdown Title

Example markdown text

{{{snippet 'example'}}}

## Another Markdown Title

The above code will look for a snippet in the page’s collection _snippets folder called example.html. If it doesn’t find it, it will look for the snippet in the global [sourcePath]/pages/_snippets folder.


config

Returns the value of a property in the coppersmith.json file.

Usage:

{{config 'property.to.return'}}
Example:
<a class="navbar-brand" href="{{config 'base'}}">{{config 'name'}}</a>

option

Similar to config, but returns the value of a property in the coppersmith.json file options property.

Usage:

{{option 'property.to.return'}}
Example:
Copyright © {{option 'copyright_year'}} <a href="{{option 'copyright_url'}}">{{option 'copyright_display'}}</a>.

has

Checks whether a config property is set in coppersmith.json file.

Usage:

{{#has 'property.to.check'}}
    _do something_
{{/has}}
Example:
{{#has 'googleCode'}}
    <script>
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

        ga('create', '{{config 'googleCode'}}', 'auto');
        ga('send', 'pageview');
    </script>
{{/has}}

skin

Returns the value of the coppersmith.json file template.skin property.

Usage:

{{skin}}
Example:
<body class="{{skin}}">
...
</body>