ms-seo icon indicating copy to clipboard operation
ms-seo copied to clipboard

Scoping Issue?

Open NewETown opened this issue 10 years ago • 3 comments

I'm seeing a weird issue in Meteor 1.0.3 where SEO.set({ ... }); isn't able to see my local post variable. Code below:

onAfterAction: function() {

        if (!Meteor.isClient) {
            return;
        }

        var post = this.data();
        SEO.set({
            'title': post.title,
            'meta': {
                'description': post.short
            },
            'og': {
                'title': post.title,
                'description': post.short,
                'image': post.image_url
            }
        });
    }

Exception in callback of async function: TypeError: Cannot read property 'title' of undefined (this is throwing at the first call of post.title)

The data exists, if I do console.log(post) I can see everything I'm looking for. Any suggestions?

NewETown avatar Mar 19 '15 13:03 NewETown

This is what i do

(function(title, description) {
      SEO.set({
        title: title,
        meta: {
          'description': description
        },
        og: {
          'title': title,
          'description': description
        }
      });
    })(data.title, description);

struCoder avatar Apr 13 '15 02:04 struCoder

@struCoder Thanks for that, turns out the "onAfterAction" function was running twice so I just throw a if this.data() == undefined check above SEO.set

Follow-up question. Am I supposed to call this in onAfterAction...? Looking up my pages in Facebook's Open Graph debugger I can't see any of the info I need:

https://developers.facebook.com/tools/debug/og/object/

Try entering http://beta.untuckedstyle.com/drinks/tequila%20and%20weight%20loss

NewETown avatar Apr 18 '15 21:04 NewETown

@NewETown Would you mind sharing the code you used to avoid the SEO.set triggering the onAfterAction twice? Thank you!

jasonshouse avatar Jun 09 '15 20:06 jasonshouse