Julian Samarjiev
Julian Samarjiev

Reputation: 499

Template not defined - Meteor

I just started creating a Meteor app and added the dburles:google-maps package, I seem to have been following the steps he indicates in the tutorial of how to implement it, but I get the error Template not defined, my code is as follows:

.html

<head>
  <meta charset="utf-8">
  <title>project-j</title>
  <meta name="description" content="Let's see where it takes us">
  <meta name="viewport" content="user-scalable=no, initial-scale=1, minimal-ui, maximum-scale=1, minimum-scale=1" />
</head>

<body>
  {{> map}}
</body>


<template name="map">
  <div class="map-container">
    {{> googleMap name="map" options=mapOptions}}
  </div>
</template>

.js

Meteor.startup(function() {
  GoogleMaps.load();
});

Template.map.helpers({
  mapOptions: function() {
    if (GoogleMaps.loaded()) {
      return {
        center: new google.maps.LatLng(-37.8136, 144.9631),
        zoom: 8
      };
    }
  }
});

Any ideas, I checked the finished repo and the code seems to be 1:1 with mine...?

Upvotes: 0

Views: 143

Answers (1)

Michael Mason
Michael Mason

Reputation: 932

You need to put the client code either in a /client folder or wrapped in a check for Meteor.isClient:

if (Meteor.isClient) { 

    Meteor.startup(function() {...});

    Template.map.helpers({ ... });

}

If not, Meteor will run your code on the client and server, and Template is not defined on the server.

You can find more information about structuring your Meteor app at http://docs.meteor.com/#/full/structuringyourapp

Upvotes: 1

Related Questions