Meteorアプリケーションの<title>
要素を変更する方法はありますか?テンプレートは<body>
でのみ処理されているようです。Meteor - 文書のタイトルを設定する
答えて
ほとんどどこでもあなたのクライアント側のJavaScriptコード内:
UI.registerHelper "setTitle", ->
title = ""
for i in [0..arguments.length-2]
title += arguments[i]
document.title = title
undefined
やJsの中に同じ:あなたはタイトル(のCoffeeScript)を設定するためのヘルパーを作成することができます
document.title = "My new title";
UI.registerHelper("setTitle", function() {
var title = "";
for (var i = 0; i < arguments.length - 1; ++i) {
title += arguments[i];
}
document.title = title;
});
複雑な方法で使用すると反応します:
{{#if book}}
{{setTitle book.title}}
{{else}}
{{setTitle "My books"}}
{{/if}}
あなたはデビッドWihlのソリューション拡張することができます。そして、あなたはいつでもコールにすることができます
Deps.autorun(function(){
document.title = Session.get("DocumentTitle");
});
を:
Session.set("DocumentTitle","New Document Title");
この回答をLove! –
https://github.com/oortcloud/unofficial-meteor-faq#how-do-i-get-reactive-html-in-the-head-tag – jefeman
私はルータに直接の事のようなものを処理するために、それはより便利見つけますonBeforeAction
:
Router.map(function() {
return this.route('StudioRoot', {
path: '/',
onBeforeAction: function() {
return document.title = "My Awesome Meteor Application";
}
});
});
テンプレート内に存在しない<head> </head>
のタグに含まれています。あなたはメタタグと一緒にタイトルを処理するためのパッケージmanuelschoebel:ms-seoを追加することができますiron:router使用する場合
<head>
<title>my title</title>
</head>
<body>
...
</body>
<template name="mytemplate">
...
</template>
:sample.htmlの
内容:これを試してみてください。 Meteor.isClientで
::私がやってしまった何を
Router.map(function() {
return this.route('blogPost', {
path: '/blog/:slug',
onAfterAction: function() {
var post = this.data().post;
SEO.set({
title: post.title,
meta: {
'description': post.description
},
og: {
'title': post.title,
'description': post.description
}
});
}
});
});
:今VARが反応的に設定されていることを
Meteor.startup(function() {
Deps.autorun(function() {
document.title = Session.get('documentTitle');
});
});
が、中に行くこれは、静的および動的なSEOデータに便利ですルータファイル(まだ実行されていない場合:meteor add iron:router。ルータファイルはクライアントとサーバの両方です)
Router.route('/', {
name: 'nameOfYourTemplate',
onBeforeAction: function() {
Session.set('documentTitle', 'whateverTitleIWant');
this.next(); //Otherwise I would get no template displayed
}
});
It既にheadタグにタイトルを設定していても問題ありません。これは、あなたのルートに従ってこのものに置き換えられます。
いくつかの問題はありませんが、セッション変数ページをリフレッシュしても生き残ることはできません。 –
@Durham、リフレッシュでルートは再び実行されます。 – BudgieInWA
私はui-routerでうまくいく答えを探す必要がありました。私はこれがあなたが探していた答えではないかもしれないことを知っています。この質問は、約2年前に投稿されましたので、私は他の誰かがUI-ルータと解決策を探してここに来たならば、この答えは彼らを助けることができる考え出し:
myApp.run.js
(function() {
'use strict';
angular
.module('myApp')
.run(run);
run.$inject = ['$rootScope', '$state'];
function run($rootScope, $state) {
$rootScope.$on("$stateChangeSuccess", function(previousRoute, currentRoute){
document.title = 'myApp - ' + currentRoute.data.pageTitle;
});
};
})();
ルート。js
(function() {
'use strict';
angular
.module('myApp')
.config(config);
config.$inject =
['$urlRouterProvider', '$stateProvider', '$locationProvider'];
function config($urlRouterProvider, $stateProvider) {
// ...
$stateProvider
.state('home', {
url: '/',
templateUrl: 'client/home/views/home.ng.html',
controller: 'HomeController',
data: {
pageTitle: 'My Dynamic title'
}
})
}
})();
なぜこれが控除されたのですか? –
Angular.jsの例をMeteor.js関連の質問スレッドに投稿したためです。 –
- 1. GoogleドキュメントAPI:文書のタイトルを設定できません。
- 2. 設定plistのタイトルを設定する
- 3. Meteor jsローカルコレクション文書を解析する
- 4. Reactで文書のタイトルをどのように設定しますか?
- 5. 動的にマスターページの本文タイトルを設定する
- 6. Visual StudioとMeteorを設定する
- 7. 文書タイトルとセクションタイトルを区別する
- 8. iosのバックバーボタンアイテムのタイトルを設定する
- 9. Active Adminの設定文書
- 10. navigationItemのタイトルを設定する
- 11. Semantic.JSでアコーディオンのタイトルを設定する
- 12. NotificationManagerのタイトルを設定するには?
- 13. UIButtonのタイトルを設定する
- 14. AppBarのタイトルを設定する
- 15. オンザフライでタブのタイトルを設定する
- 16. Excelスプレッドシートワークシートのタイトルを設定する
- 17. ナビゲーションバーのタイトルを設定する方法
- 18. MFMailComposeViewControllerのタイトルをNILに設定する
- 19. コンテキストアクションバーのタイトルを設定する
- 20. UITabBarのタイトルを設定する
- 21. シャイニーダッシュボードのタイトル/ヘッダーを設定
- 22. カスタムアラートダイアログのタイトルと(タイトル)アイコンを設定する
- 23. XSLT文書の書式設定
- 24. 設定タイトル、効果
- 25. Purescriptを使用して文書のタイトルを設定するにはどうすればよいですか?
- 26. UITableView内からタイトルを設定する
- 27. WePopoverControllerでタイトルとUIBarButtonItemを設定する
- 28. Meteorを使用してサブ文書の特定のフィールドを返す
- 29. ウィンドウポップアップでタイトルを設定
- 30. Jasperビューアの設定タイトル
ありがとう、ありがとう。 –