Last active
December 15, 2015 14:48
-
-
Save ducin/5276720 to your computer and use it in GitHub Desktop.
ICanHaz.js `grabTemplates()` demo (see more at http://symfony-world.blogspot.com/2013/03/icanhazjs-grabtemplates-example.html). Example shows how you can load additional templates using ajax and reload ICanHaz container to use them. Note that the ajax call should be synchronous.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready( function() { | |
$.ajax({ | |
type: "GET", | |
dataType: 'text', | |
async: false, | |
url: "templates.html" | |
}).done(function(response) { | |
$("body").append(response); | |
ich.grabTemplates(); | |
}); | |
$('#display').click(function () { | |
var message = ich.displayMessage({'name': 'tkoomzaaskz'}); | |
$('#container').append(message); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/tr/html4/transitional.dtd"> | |
<html> | |
<head> | |
<title>ICanHaz.js grabTemplates demo</title> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/ICanHaz.js/0.10/ICanHaz.min.js"></script> | |
<script type="text/javascript" src="ajax-ich.js"></script> | |
</head> | |
<body> | |
<p> | |
Once the document is ready, templates are loaded via ajax and | |
appended to the end of the body tag. <code>ich.grabTemplates()</code> | |
loads them into ICanHaz. | |
</p> | |
<button id="display">click to add message</button> | |
<div id="container"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script id="displayMessage" type="text/html"> | |
<p> | |
Hello {{ name }} ajax call succeeded! | |
</p> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment