question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Link-to helper doesn't like class conditions

See original GitHub issue

I am trying to use class conditions with a link-to helper, but fails on compilation.

link-to view.linkName lnid urlSlug itemprop="url" class={view.isSelected:selected view.icon} doesnt work.

link-to view.linkName lnid urlSlug itemprop="url" class=view.isSelected:selected doesnt work either.

a href="#" class={view.isSelected:selected view.icon} works fine.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
thec0kemancommented, Sep 16, 2015

Inside mustache you need to use Ember’s inline if:

= link-to linkName lnid urlSlug itemprop="url" class=(if isSelected selected)
=>
{{link-to linkName lnid urlSlug itemprop="url" class=(if isSelected selected)}}

Some things to keep in mind:

  • { } are for wrapping things in mustache. In a link-to you are already in a mustache context, so these won’t work.
  • Binding things to class or classNames is very different than classNameBindings. The inline approach should still work for the latter.
  • with the latest versions of Emblem, colon syntax gets mapped to the inline if for html tags but not mustache:
a class=isActive:active:not   =>   <a class={{if isActive 'active' 'not'}}></a>

I’m pretty sure the old colon syntax of isActive:active:inactive is not supported anymore by Ember.

0reactions
thec0kemancommented, Jun 30, 2016

Actually, that latter case is expected. Components / helpers should be able to receive single arguments, and so without a | or a new-line there is no way to know when the helpers parameters end.

@Leooo @kandebonfim could you confirm if the above examples work for you? Or is there a variation that is not working?

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rails link_to_if Class Doesnt Display Correctly - Stack Overflow
The image displays, with no link as expected, but the CSS class defined at the end does not, instead it just has no...
Read more >
link_to (ActionView::Helpers::UrlHelper) - APIdock
Creates an anchor element of the given name using a URL created by the set of options. See the valid options in the...
Read more >
Problems parsing link-to with class names · Issue #282 · machty ...
Seems like adding an underscore in class name causes some misunderstanding in emblem's link parser. ... Link-to helper doesn't like class conditions #145....
Read more >
Module ActionView::Helpers::UrlHelper - Rails API
Creates a link tag of the given name using a URL created by the set of options unless condition is true, in which...
Read more >
Helpers - Zendesk Developer Docs
Displays a link to the page with the end user's activities. If signed in as an agent or Help Center manager, the link...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found