< head>中的Ember Handlebars模板标签 [英] Ember Handlebars Templates in <head> tag
问题描述
为了动态地更改标题标签,元标记,外部CSS样式表和图标,可以使用ember(特别是应用程序模板)来操作头文件。
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?
推荐答案
为了使这项工作我做的是我创建了车把助手。例如,如果要更改非常常见的视图的标题,这里是帮助器。
In 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 common, 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'}}
以下是 JSbin ,检查其工作是否正常
Here is the JSbin to check if its working
这篇关于< head>中的Ember Handlebars模板标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!