2017-01-19 4 views
0

私はIron Routerを使用しています。URLからパラメータを取得し、それをテンプレートファイルに配置します。私はelectronics_____を交換したいメテオのテンプレートファイルからURLパラメータにアクセスするには?

<template name="category_products"> 
    <p>Sorry, there are no _____ products.</p> 
</template> 

ので、出力は

なり申し訳ありませんが、あります。私のテンプレートファイルで

http://localhost:3000/categories/electronics

例えば:エレクトロニクス製品はありません。

答えて

1

経路を定義したと仮定すると、this.paramsを使用してパラメータを取得できます。

Router.route('/categories/:name',()=>{ 
    this.render('category_products', { 
    data: function() { 
     return { 
     cursor: Products.find({categoryName: this.params.name}), 
     category: this.params.name 
     }; 
    } 
    }); 
}); 

HTML::

<template name="category_products"> 
    {{#if cursor.count()}} 
    {{#each cursor}} 
     {{name}} 
    {{/each}} 
    {{else}} 
    <p>Sorry, there are no {{category}} products.</p> 
    {{/endif}} 
</template> 
また、複数のキーを含んでいるオブジェクトであるデータコンテキストでテンプレートを提供することができます
関連する問題