簡體   English   中英

使用URL中的默認路由器參數從html調用模板

[英]Call a template from html with default router param in URL

我有一個模板“ eventContainer”的鐵路線,其中包括一個參數,該參數根據用戶在先前模板中選擇的事件來確定。

Router.route ('/eventContainer/:_id', {
  template: "/eventContainer",
  data: function(){      
}});

一切正常。 當用戶第二次登錄時,我將“ eventContainer”模板加載為他的主頁,但是自從handlebars事件調用以來,我正在尋找一種設置路由參數的方法。 (參數應該是他們見過的最后一個事件)。

有沒有一種方法可以使用帶有路由參數的雙括號{{> eventContainer}}從html調用模板? 類似於{{> eventContainer RouterParam:xx}}嗎?

<template name="home">
  {{#if Template.subscriptionsReady}}
    {{#if notEventJoined}}
      {{> findEvent}}
    {{else}}
      {{> eventContainer}}
    {{/if}}
  {{else}}
  Loading...
  {{/if}}
</template>

和...

<template name="eventContainer">
  <!-- Here I read the Router.current().params._id -->
</template>

您可以將helper作為參數傳遞:

<template name="home">
    {{> eventContainer param}}
</template>
Template.home.helpers({
  param: function() {
    return Router.current().params._id;
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM