Antonio Pavicevac-Ortiz
Antonio Pavicevac-Ortiz

Reputation: 7729

Getting: Uncaught TypeError: Invalid template!...in mustache.js

I have been trying to implement external templates, but to no avail. This is the full error:

Uncaught TypeError: Invalid template! Template should be a "string" but "undefined" was given as the first argument for mustache#render(template, view, partials)

I am using browserify-shim for some other dependencies, but they work perfectly, and I am not getting errors (from that task) from the terminal. It's just the external template loading which is giving me problems.

function templateLoader(e) {
        var doc = document,
            event = EventUtility.getEvent(e),
            target = EventUtility.getTarget(event);
            $("body").load("templates/index.html #overlay", function() {
                var temp1 = $('#overlay').html();
                var output = Mustache.render(temp1);
                $("body").html(output);
            });

    }

var flimFlam = document.getElementById('Container');
EventUtility.addHandler(flimFlam, 'click', templateLoader);

Thanks so much in advance!

Upvotes: 3

Views: 4631

Answers (2)

B Isaac
B Isaac

Reputation: 71

because your Mustache template is probably nested in the rendering template. separate them and this error should go away.

Upvotes: 1

Rafa Calin
Rafa Calin

Reputation: 11

Try to put everything in

$(document).ready(function(){


});

I had the same error and it worked for me.

Upvotes: 1

Related Questions