DiscoverMeteor / book

17 stars 0 forks source link

Templates Chapter - domain helper - post_item.js - 'url' vs. 'URL' #439

Closed methodbox closed 9 years ago

methodbox commented 9 years ago

More of a suggestion that an actual problem.

I would strongly suggest explaining the major difference between using URL and url in the following code:

Template.postItem.helpers({
  domain: function() {
    var a = document.createElement('a');
    a.href = this.url; //lowercase matters!
    return a.hostname;
  }
});

For those of us using code completion tools and not cut/pasting directly from the book, it's pretty easy to make that mistake.

With URL, your script will grab the browser's current URL, which if you're developing locally will be localhost; url will correctly grab the value from the postsData array and display the hostname part of the url (aka the domain name).

SachaG commented 9 years ago

Sorry, I'm not really sure I understand. Isn't url just a property of the post document? Why would URL work as well?