Params not available in ViewModel

Skip to first unread message


May 18, 2015, 4:57:43 PM5/18/15
I'm new to JavaScript and Sammy development.
I am creating a SPA so we are using templates. We are also using knockout.js for data binding. I am having trouble accessing the route parameters from the viewModel. Below I have 3 snippets of code, the route, the view, and the viewModel. The email parameter is available in the route function and appears in the URL after the route is processed. However, it is not in the data variable that is expected in the view model. Data is undefined in the viewModel.

I have a javascript file (route.js) that contains the following route:
    Sammy.get('#/unconfirmeduser/:emailAddress', function (context) {
        context.render('/sandbox/aw/unconfirmeduser.html', { emailAddress: context.params.emailAddress }).replace("#contentPlaceHolder");
The view html file contains:
<p>Email not confirmed</p>
<div id="unconfirmedAccount">
    <p>Email Address: <input data-bind="value: emailAddress" /></p>
    <button data-bind="click: resend">Resend</button>
    <button data-bind="click: resend">Settings</button>
<script src="sandbox/aw/unconfirmeduser.js"></script>
<script type="text/javascript">
    ko.applyBindings(new MyCompany.viewModels.unconfirmedAccount(), document.getElementById("unconfirmedAccount"));
The viewModel script file contains:
MyCompany.viewModels.unconfirmedAccount = function (data) {
    var self = this;
    self.clientId = ko.observable();
    self.emailAddress = ko.observable(data.emailAddress);
    MyCompany.viewModels.unconfirmedAccount.prototype.resend = function () {
        var url = MyCompany.connection.getUrl("/v1/accounts/ConfirmEmailAddress");
        $.get(url, { clientId: self.clientId() }, null, "json")
            .done(function (e) {
                alert("Success Confirming email: " + e.statusText);
            .fail(function (e) {
                alert("Fail: " + e.statusText);

 If I apply the knockout binding for the view model in the route script instead of in the view, I can pass the data into the viewModel but I am told this is not best practice.
ko.applyBindings(new MyCompany.viewModels.unconfirmedAccount(), document.getElementById("unconfirmedAccount"));

The documentation has the following line of code but I cannot find any examples of where {some: data} is being accessed in the template defined in the '/location' parameter.
 this.render('/location', {some: data});
Please advise where I should be able to retrieve the data from.


Aaron Quint

May 19, 2015, 10:37:52 AM5/19/15
The template needs to be an actual template that Sammy can render through some template engine (ie a .tmpl, .haml, .mustache) and then interpolate the variables through the relevant templating syntax. Pure html files are not interpolated.


You received this message because you are subscribed to the Google Groups "Sammy.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

Reply all
Reply to author
0 new messages