user1524361
user1524361

Reputation: 4465

Passing parameters in spacebars template yields 'First argument must be a function' error

I'm trying to follow lectures on the EventedMind.com website and in the "Shark UI Preview: Rendering with the Inclusion Tag" video I'm getting this error:

First argument must be a function, to be called on the rest of the arguments; found STRING

on the asterisk'd line below in my code.html file. I presume I'm not including the right package. Here are the packages I'm currently using

meteor list --using standard-app-packages
autopublish
insecure
spacebars-compiler -- I get the same error with or without this

...and this is the version of Meteor I'm using meteor --version Release 0.8.2

================================ from code.html:

<head>
  <title>Rendering with the inclusion tag</title>
</head>

<body>
  {{> hello}}
</body>

<template name="hello">
  <h1>Hello Dan!</h1>

* {{> greeting "Joe" "Smith"}}

<template name="__greeting">
  Greetings!
</template>

==================================== from code.js

if (Meteor.isClient) {
  Template.hello.helpers({
    greeting: function(firstName, lastName){
      console.log(firstName, lastName);
      return Template.__greeting;
    }
  });
}

Upvotes: 1

Views: 5203

Answers (1)

fuzzybabybunny
fuzzybabybunny

Reputation: 5254

It doesn't have anything to do with packages.

Your complete error looks like this:

While building the application:
client/views/pages/test.html:4: First argument must be a function, to be called on the rest of the arguments; found STRING
...type="update"}}  --> {{> greeting "Joe...
                        ^

Look at the ^ in the error message.

It's saying that your first argument after {{> greeting needs to be a function. Instead it got a string, "Joe". So you're not calling your spacebars helper correctly.

Try {{> greeting firstName="Joe" lastName="Smith"}}

Reference: https://www.discovermeteor.com/blog/spacebars-secrets-exploring-meteor-new-templating-engine/

Upvotes: 1

Related Questions