{{#routeCurrent hash}}

  • function
can.stache.helpers.routeCurrent  

Returns if the hash values match the can.route's current properties.

{{#routeCurrent hashes}}SUBEXPRESSION{{/routeCurrent}}

Renders SUBEXPRESSION if the hashes passed to can.route.current returns true. Renders the {{else}} expression if can.route.current returns false.

Parameters

  1. hashes {Expressions}

    A hash expression like page='edit' recipeId=id.

Returns

{String}

The result of SUBEXPRESSION or {{else}} expression.

routeCurrent([hashes])

Calls can.route.current with hashes and returns the result.

Parameters

  1. hashes {Expressions}

    A hash expression like page='edit' recipeId=id.

Returns

{Boolean}

Returns the result of calling can.route.current.

Use

Use the routeCurrent helper like:

<li {{#routeCurrent page="recipe" id=5}}class='active'{{/routeCurrent}}>
  <a href='{{routeUrl page="recipe" id=5}}'>{{recipe.name}}</a>
</li>

With default routes and a url like #!&page=5&id=5, this produces:

<li class='active'>
  <a href='#!&page=5&id=5'>{{recipe.name}}</a>
</li>

It this functionality could use call expressions like:

<li {{#routeCurrent(page="recipe" id=5)}}class='active'{{/routeCurrent}}>
  <a href='{{ routeCurrent(page="recipe" id=5) }}'>{{recipe.name}}</a>
</li>

The following demo uses routeCurrent and {{routeUrl hashes}} to create links that update can.route's page attribute:

It also writes out the current url like:

{{ routeCurrent(undefined,true) }}

This calls can.route.url({}, true) which has the effect of writing out the current url.