I am using mustache templating engine with jquery mobile. I cannot figure out why my html is not formatting correctly with jqm. Here is my html/script:
<body>
<div id="john" data-role="page">
<div id="header" data-role="header"></div>
<div id="content" data-role="content"></div>
<div id="footer" data-role="footer"></div>
</div>
<script>
var data = {
technique : "Knee Slide Pass",
steps : ["Step 1", "Step 2", "Step 3"],
msg : "Hard Works Pays Off"
};
$.get('template.html', function(templates) {
var header = $(templates).filter('#tpl-header').html();
var content = $(templates).filter('#tpl-content').html();
var footer = $(templates).filter('#tpl-footer').html();
$('#header').html(Mustache.to_html(header, data));
$('#content').html(Mustache.to_html(content, data));
$('#footer').html(Mustache.to_html(footer, data));
//$('#footer').html(Mustache.to_html(footer, data)).trigger('create');
//$this.trigger('create').trigger('refresh').page();
});
</script>
</body>
Here is my template.html:
<div id="tpl-header">
<h1>{{technique}}</h1>
</div>
<div id="tpl-content">
<ul id="loader">
{{#steps}}
<li>
{{.}}
</li>
{{/steps}}
</ul>
</div>
<div id="tpl-footer">
<h1>{{msg}}</h1>
</div>
The resulting web page does have a header and footer with content. However, the header is very big and to the left(same with footer). If i just hard code the header and footer in html, it works. But when jqm updates the html, it doesn't get formatted correctly. I have read to add .trigger('create') but doesn't work. Can anyone please help, I have been working on this for way too long. Thanks in advance!
John