2015-07-04 77 views
0

我在包中使用鐵路路由器,它抱怨說它找不到模板,即使我已經定義了它。內部包裝中的鐵路路由器:找不到模板

我已經定義了一個名爲layout我的包裏面的模板:client/templates/shared/layout.html

而且我要求文件中package.js這樣的:

Package.onUse(function(api) { 
    api.versionsFrom('1.1.0.2'); 

    api.use('iron:[email protected]'); 

    api.addFiles([ 
    'both/routes.js' 
    ], ['client', 'server']); 

    api.addFiles([ 
    'client/templates/shared/layout.html', 
    'client/templates/home.html' 
    ], 'client'); 
}); 

而且我用我的路線定義文件layout模板, both/routes.js

Router.configure({ 
    layoutTemplate: 'layout' 
}); 

Router.route('/', { 
    name: 'home', 
    template: 'home' 
}); 

而在我的主應用程序中,我正在使用這個軟件包。它可以在.meteor/packages找到。

但是,當我瀏覽到/,我得到

Couldn't find a template named "layout" or "layout". Are you sure you defined it? 

我試圖重新啓動沒有成功的服務器。我錯過了什麼?

+0

胡亂猜測,請嘗試使用'api.addFiles'包文件內的路由器文件,然後再添加HTML文件??? – Sasikanth

+0

@Sasikanth我嘗試了所有與'api.use'和兩個'api.addFiles'的組合,但無法使它工作。 –

回答

1

您可能還需要以下兩個:

api.use(['templating'], 'client'); // The templating package

api.export('layout' ['client', 'server']); // Export your template.

+0

添加'api.use('模板','客戶');'做了詭計。對於任何有類似問題的人,請參閱[模板](https://github.com/meteor/meteor/tree/devel/packages/templating#templating) –