Last active
December 15, 2015 04:09
-
-
Save stevepeak/5199549 to your computer and use it in GitHub Desktop.
Generate Hogan templates on Bootstrap on the fly.
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).on('click', '[data-toggle][data-template]', function(){ | |
var target = $($(this).attr('data-target') || $(this).attr('href')); | |
if( !$(target).data('hogan-template') ){ | |
$(target).data('hogan-template',Hogan.compile(target.html()));} | |
target.html($(target).data('hogan-template').render($.parseJSON($(this).attr('data-template')))); | |
}); |
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
<a href="#modal" data-toggle="modal" class="btn btn-small" data-template='{"title":"Hello","body":"Some stuff.","more":"more data"}'>Open</a> | |
<a href="#modal" data-toggle="modal" class="btn btn-small" data-template='{"title":"Yo!","body":"Put your juicy stuff here.","more":"more..."}'>Open 2</a> | |
<div id="modal" class="modal hide fade"> | |
<div class="modal-header"><h3>{{title}}</h3></div> | |
<div class="modal-body"> | |
<p>{{body}}</p> | |
{{more}} | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is a quick and easy way to render templates on the fly.
This will on the fly generate the html content. All of Hogan template methods work.