Usage: {{#link href="/about/"}}About{{/link}}
Description
{{#link}}
is a block helper that creates links with dynamic classes. In its basic form it will create an anchor element that wraps around any kind of string, HTML or handlebars constructed HTML.
With additional options it can have an active class
or target
behaviour, or onclick
JavaScript events. A href
attribute must be included or an error will be thrown.
Simple example
All attributes associated with the <a></a>
element can be used in {{#link}}
. Check out the MDN documentation on the anchor element for more information.
Variables
Handlebars variables can be used for attribute values as well as strings. Variables do not need be wrapped with quotations:
Simple variables example
Advanced variables example
Dynamic attributes
activeClass
By default the active class outputted by {{#link}}
will be nav-current
, this is consistent with our navigation helper. However it can be overwritten with the activeClass
attribute:
activeClass
Example
activeClass
can also be given false
value (activeClass=false
), which will output an empty string. Effectively turning off the behaviour.