meteor - How to fetch query parameters in a template? -
i using meteor 1.2.1 + iron-router autopublish turned on
i construct anchor href based on collection values returned helper and query params
is possible in template tag, e.g. query_param1
should read url?
<template name="dataentry"> {{#each data}} <li> <a href="/listing?name={{name}}&color=<query_param1>"> data name </a> </li> {{/each}} </template>
above, {{name}}
returned collection , query parameters appended create full hyperlink href
.
you can use @stephen's suggestion this.
in template html,
<template name="dataentry"> {{#each data}} <li> <a href="/listing?{{queryparams}}"> data name </a> </li> {{/each}} </template>
in template js,
template.dataentry.helpers({ "queryparams": function () { var name = ""; //get name collection here like... //name = meteor.user().profile.firstname; var color = router.current().params.color; return "name=" + name + "&color=" + color; } });
or can use 2 separate helpers
in template html,
<template name="dataentry"> {{#each data}} <li> <a href="/listing?name={{name}}&color={{color}}"> data name </a> </li> {{/each}} </template>
in template js,
template.dataentry.helpers({ "name": function () { var name = ""; //get name collection here like... //name = meteor.user().profile.firstname; return name; }, "color": function () { return router.current().params.color; } });
Comments
Post a Comment