Meteor – How to use template helpers inside <head> element?
Asked Answered
V

2

16

I want to be able to use Meteor template helpers to dynamically specify the content of a <meta> tag. It seems like there is no way to do this.

If I put the <meta> tag in a free-floating <head> element (i.e. not in a template), both will be included correctly in the HTML, but I can't use template helpers.

If I move the <meta> to a template, and try to render the template within a free-floating <head> element, it complains.

And if I move the whole <head> element into a template, now I have a <head> block nested within the <body>, which is ugly, and I suspect invalid HTML (though Chrome seems to handle it gracefully).

Is there a solution?

Vitreous answered 25/4, 2014 at 23:36 Comment(4)
Can you just update it with jQuery?Delapaz
No, because the reason I want to do this is for cases when the client is only going to pay attention to the initial headers (e.g. Facebook OG).Vitreous
Any update on this. It is one year since, and no solution yet?Bretbretagne
mb this can help: #29972819Laterality
H
12

It is not currently possible to this without post load insertion due to they way Meteor parses templates

Hatpin answered 26/4, 2014 at 17:46 Comment(0)
W
0

Just to bump an old thread as this is now possible on initial page load, you can try out this package https://atmospherejs.com/pip87/initial-iron-meta not tested it outside my environment much but seems to work well. Was hacked apart from kadiras fast render to handle og tags etc getting inserted onto initial page load only so it, doesn't handle switching between pages at the moment only renders for the initial page load which was what I wanted for seo bots. Also needs iron router to work.

Data gets injected from the server side call to the route in the same way the iron routers fast-render package works

I wouldn't recommend this on its own as some bots like Google will penalise if the content isn't available so having ssr or spiderable for seo bots is defiantly advisable to offer a fully rendered page to the bot, this package was meant as more of a fallback for non ajax supporting bots and those only interested in head tags

Winstonwinstonn answered 29/2, 2016 at 17:51 Comment(3)
Careful : Iron router is not the recommended router anymore : Flow router is, and for good reasons. That being said... this is a valid solution :)Exorcism
To be fair they are completely different so it's not as black and white as one or other. Iron router is still a valid tool if you want to have server side routing/REST as to my knowledge flow have said it will never be included. I know there are other packages but with IR the cleaner code and easier ssr still wins me over. Besides it's only no longer recommended not dangerous to use just gotta work round it rather than with it sometimes ;)Winstonwinstonn
I admit I am more fond of Flow Router but everything you said is more than validExorcism

© 2022 - 2024 — McMap. All rights reserved.