我在設置不同網頁的簡單網站時遇到問題並且保持乾燥。DRY用於顯示不同網址的流星模板
我已經設置了一切,所以我的網址的最後一個片段是需要加載到網頁內容部分的模板的名稱。我現在要做的就是根據url在特定位置加載該模板。
在任何的例子,他們這樣做:
{{#if showCreateDialog}}
{{> createDialog}}
{{/if}}
{{#if showInviteDialog}}
{{> inviteDialog}}
{{/if}}
我想一起做的
{{> {{template_name}} }}
可悲的是,這並不工作線的東西。無論是
{{{content}}}
Template.content.content = function() {
var url_frag = Session.get("url_frag");
return Template[url_frag]();
}
這沒有工作:我想這一點。請幫忙!
編輯:
哼。也許,我的錯誤是在不加載模板,但在拍攝的網址:
var TodosRouter = Backbone.Router.extend({
routes: {
"*url": "main"
},
main: function (url) {
Session.set("url", url.split('/'))
}
});
時url_frag是不確定的,我得到的錯誤出現...
var url_frag = Session.get("url_frag");
最初,這個工作,但在改變網頁,它失敗...
我覺得你的模板使用[名](),結合{{{}}}應該工作。 下面是一個使用示例:https://github.com/meteor/meteor/blob/master/packages/accounts-ui-unstyled/login_buttons_dialogs.js#L223和https://github.com/meteor/ meteor/blob/master/packages/accounts-ui-unstyled/login_buttons_dialogs.html#L71 – avital
感謝您的幫助。檢查我的編輯。我可能已經指出了錯誤在別處。 – chet