Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 385
Antonio Pavicevac-Ortiz Avatar asked May 29 '26 03:05

Antonio Pavicevac-Ortiz


2 Answers

Try to put everything in

$(document).ready(function(){


});

I had the same error and it worked for me.

like image 71
Rafa Calin Avatar answered May 31 '26 17:05

Rafa Calin


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

like image 43
B Isaac Avatar answered May 31 '26 16:05

B Isaac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!