ember-cli-meta-tags icon indicating copy to clipboard operation
ember-cli-meta-tags copied to clipboard

Support headTags Promises

Open ianpetzer opened this issue 9 years ago • 4 comments

Is there a way to use async relationships in the headTags function?

Currently if I refer to an async relationship, then i get undefined show up in the meta tag, and I can't return a promise from headTags function.

ianpetzer avatar Nov 21 '15 07:11 ianpetzer

Hey @ianpetzer,

Good question. I like the idea of understanding a promise in headTags. It gets a little complicated in the implementation, but I'll be thinking about how it might be done. As always pull requests are welcome if you want to take a crack at it.

I think there are a couple of approaches you could use to get this working with the addon in it's current state:

  1. If you're ok with your route transition blocking until all of your async relationships resolve you could chain the promises in your model hook, or use the afterModel hook to fetch all the async relationships. This will ensure all your data is loaded by the time headTags is called.
  2. If you don't want to block your transition take a look at Resetting Tags Outside of Transition. This will let you re-populate the headTags at an arbitrary time.

Let me know if either of those work for you. I'm happy to elaborate more if you'd like.

-Ron

ronco avatar Nov 21 '15 15:11 ronco

Ron,

Thanks so much for getting back to me. I actually implemented the first suggested solution before contacting creating this issue.

I think the second option is a great idea, so I don't need to block the transition.

Thanks for the great ideas.

On Sat, Nov 21, 2015 at 5:17 PM, ronco [email protected] wrote:

Hey @ianpetzer https://github.com/ianpetzer,

Good question. I like the idea of understanding a promise in headTags. It gets a little complicated in the implementation, but I'll be thinking about how it might be done. As always pull requests are welcome if you want to take a crack at it.

I think there are a couple of approaches you could use to get this working with the addon in it's current state:

If you're ok with your route transition blocking until all of your async relationships resolve you could chain the promises in your model hook, or use the afterModel hook to fetch all the async relationships. This will ensure all your data is loaded by the time headTags is called. 2.

If you don't want to block your transition take a look at Resetting Tags Outside of Transition https://github.com/ronco/ember-cli-meta-tags#resetting-tags-outside-of-transition. This will let you re-populate the headTags at an arbitrary time.

Let me know if either of those work for you. I'm happy to elaborate more if you'd like.

-Ron

— Reply to this email directly or view it on GitHub https://github.com/ronco/ember-cli-meta-tags/issues/28#issuecomment-158651675 .

ianpetzer avatar Nov 22 '15 06:11 ianpetzer

Great @ianpetzer! I'm glad that helped out. I'm going to keep this issue open as a possible enhancement. I like the idea of supporting promises out of the box (although the complexities might keep me from building a solution anytime soon).

ronco avatar Nov 23 '15 21:11 ronco

This would be incredibly helpful in fastboot

Duder-onomy avatar May 23 '18 22:05 Duder-onomy