54

I try to build a link to a nested route and want to add a class to this link (for twitter bootstrap)

The result should something like this:

< a href="/#/rents/42" class="btn btn-primary btn-small">do something< /a>

First try:

{{#link-to "rent" rent}}

gives me a link to the ressource but I cannot specify a (css) class. In the docs I see that only the title attribute can be specified

Second try:

< a href="/#/rents/{{rend.id}}" class="btn btn-primary btn-small">do something< /a>

is also a bad idea, because Ember will add its helper tags [for automatic updates] in the href.

So what can I do?

3 Answers 3

110

Use:

{{#link-to 'rent' rent class='btn btn-primary btn-small'}}Go to rent{{/link-to}}

As link-to is a view helper.

Sign up to request clarification or add additional context in comments.

3 Comments

awesome! I didn't knew I could add view attributes to the helpers.
This does not work in version 1.13.7 of ember anymore as it fails to add the ember-view class, without wich it will just be a normal link and reload the page. Using just class="btn btn-primary etc" as proposed in Connors answer below works as expected.
Thanks for the heads up
11

You can add classes just fine in {{#linkTo}} helpers, you just need to remember not to confuse ember.

Ember may think your class is the routeName of the params, I include the class after both params and routeName and it works fine.

{{#linkTo 'dashboard.screenshots' value.model class='thumbnail'}}
   ........
{{/linkTo}}

Produces

<a id="ember507" class="ember-view thumbnail" href="#/project-2/member-1/task-2/screenshot-30">
   .........
</a>

Comments

1

If you want manually construct something from variables - there is {{unbound}} helper in ember.js.

In yor case code will looks like:

<a href="/#/rents/{{unbound rend.id}}" class="btn btn-primary btn-small">
   do something
</a>

1 Comment

You should be using {{#link-to}} helper.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.