我正在使用模板來生成流星中的HTML標記屬性,但似乎被打破。我無法在meteor的HTML標籤中放置模板,我想知道原因。如何使用模板在流星中生成動態HTML標記屬性?
我使用meteor-router進行路由。由於流星基本上只允許一個佈局,我想一個類補充人體表示當前視圖名稱,像這樣:
/client/layout.html:
<head>
<title>Meteor App</title>
</head>
<body {{> body-attributes}}>
{{renderPage}}
</body>
<template name="body-attributes">data-view-name="{{page}}" class="{{page}}"<template>
,這樣我可以做這/client/layout.js:
Template['body-attributes'].page = function() {
return Meteor.Router.page();
};
但沒有工作,我得到了應用程序的說法對身體屬性是不支持的錯誤。將layout.html更改爲:
<head>
<title>Meteor App</title>
</head>
<body>
<div {{> body-attributes}}>
{{renderPage}}
</div>
</body>
<template name="body-attributes">data-view-name="{{page}}" class="layout-container {{page}}"<template>
導致完全損壞的HTML。瀏覽器在頁面前顯示'>',控制檯元素面板如下所示:
爲什麼不能正常工作?
謝謝,我將你的答案標記爲答案,並且會說人們應該檢查[我的回答](http:// stackoverflow。(14072774/using-a-template-to-generate-html-tag-attributes-in-meteor-is-broken/14072874#14072874)來解決這個問題。 – Diogenes