Help contribute to Ember: non-block form linkTo

Rather than differentiating if the arguments are strings vs. ids, how about if it’s a non-block, expect the first argument to be the title. Otherwise, expect the first argument to be a route?

That’s exactly what I’m doing at the moment.

// If a block is not given.
if(!options.fn) {
  // Set the namedRoute param to the second argument.
  hash.namedRoute = arguments[1];

  // Check to see if the type of the first argument is ID (which means it is unquoted).
  if(options.types[0] === "ID") {
    // Then look it up on the current context.
    linkText = get(this, linkText);
  }

  options.fn = function() { return linkText; };

  params = [].slice.call(params, 1);
} else {
  // Code for when a block is present.
}

The thing is, params are passed in LinkView to Ember.Handlebars.resolveParams which as I described checks against params type and then pushes the object resolved by looking up the context (in case the param type is an ID, of course) back into resolvedContexts array which is then used to render the href attribute in the link. Also, resolveParams is used by other helpers to check against their params so I’m not really in favor of changing it directly.

Hmm, can any of you guys, point out where I’m going wrong with this? cc: @wycats @tomdale @trek @pwagenet @stefan @ebryn

The options.types array isn’t getting adjusted. I’m not sure if it’s safe to modify options, but I tried adding this line:

options.types = [].slice.call(options.types, 1);

inside your condition, and it’s still not working.

I’m with you, that resolveParams et al are kind of complicated. I tried making a view that extended LinkView before, by-passing the linkTo helper, and it didn’t work out as easily as I’d expected because of the way it resolves params.

the issue that I’m having with:

{{#each articles}}
  {{linkTo title 'articles.show' this}}
{{/each}}

is that in the link-to helper, ‘this’ makes reference to the article and not the controller, like in the others tests, so, my test is braking because it doesn’t find the route in the current context which is the article and not the controller, that’s what I guess.

You should be using Ember.Handlebars.get for that, which knows how to get values off of keywords and other data available at render time.

@machty I took up the development of this feature and made a pull request

Yehuda merged in the PR last night. Thanks @balint for seeing it through!

2 Likes