【问题标题】:pass the current path as argument in a meteor template将当前路径作为流星模板中的参数传递
【发布时间】:2026-02-05 08:45:01
【问题描述】:

如何在流星模板中传递当前路径

{{> sometemplate somearg="{{currentpath}}" }}

当前路径基本上是window.location.pathname返回的路径

【问题讨论】:

    标签: meteor


    【解决方案1】:

    您可以为此使用一个简单的助手:

    Template.parentTemplate.helpers({
      currentPath: function() {
        return window.location.pathname;
      }
    });
    

    然后在你的模板中调用它:

    <template name="parentTemplate>
      {{!-- ... --}}
      {{> sometemplate somearg=currentPath }}
    </template>
    

    【讨论】:

    • 不幸的是,它不起作用。如果我让它将路径名打印到控制台,我认为问题是meteor在帮助程序运行后的某个时间更新了位置,因此在执行函数时它的路径名错误。