admin管理员组文章数量:1400776
Is it possible for ember (specifically the application template) to operate inside the head tag in order to dynamically change things like the title tag, meta tags, external css stylesheets and the favicon?
If so, what would be a clean way of doing this?
Is it possible for ember (specifically the application template) to operate inside the head tag in order to dynamically change things like the title tag, meta tags, external css stylesheets and the favicon?
If so, what would be a clean way of doing this?
Share Improve this question edited Aug 29, 2013 at 1:59 Bradley Trager asked Aug 26, 2013 at 13:15 Bradley TragerBradley Trager 3,5903 gold badges28 silver badges33 bronze badges 5-
1
Curious about this as well. In angular.js it's roughly as simple as
<html ng-app>
– Donut Commented Aug 28, 2013 at 20:32 -
using this its simply easy,
document.getElementsByTag("head").innerHTML += "<meta content = ''/>";
this can be achieved with raw JavaScript so why to rely on any library :) – MarmiK Commented Aug 29, 2013 at 6:35 - 3 @MarmiK he asked for a "clean" way :P – albertjan Commented Sep 2, 2013 at 13:17
- @MarmiK When the dom is loaded most of the meta tags are loaded and has no effect even if you change them after in javascript. So I guess he asked before loading the whole page. Since ember creates its index.html page and everything is then done in body how to increase your seo, etc, because they won't execute javascript – Sahib Khan Commented Dec 2, 2017 at 3:46
- Possible duplicate of Setting page title with ember.js – Liam Commented Dec 7, 2018 at 13:37
1 Answer
Reset to default 10 +50In order to make this work, what I did was I created handlebar helpers. For Example, If you want to change the title for views which is very mon, here is the helper.
Ember.Handlebars.helper('headTitle', function(title) {
Ember.$('head').find('title').text(title);
}, 'title');
now in any view template you can just add the helper
{{headTitle 'View Header'}}
Here is the JSbin to check if its working
本文标签: javascriptEmber Handlebars Templates in ltheadgt tagStack Overflow
版权声明:本文标题:javascript - Ember Handlebars Templates in <head> tag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744280429a2598623.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论