can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
66 lines (41 loc) • 1.86 kB
Markdown
7
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 can.route.current] returns `true`.
Renders the [can.stache.helpers.else] expression if [can.route.current can.route.current] returns `false`.
{can.stache.expressions} hashes A hash expression like `page='edit' recipeId=id`.
{String} The result of `SUBEXPRESSION` or `{{else}}` expression.
`routeCurrent([hashes])`
Calls [can.route.current can.route.current] with `hashes` and returns the result.
{can.stache.expressions} hashes A hash expression like `page='edit' recipeId=id`.
{Boolean} Returns the result of calling [can.route.current 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 [can.stache.helpers.routeUrl] to
create links that update [can.route]'s `page` attribute:
can/view/stache/doc/helpers/route-url.html
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.
can.stache.helpers.routeCurrent {{#routeCurrent hash}}
can.stache.htags