I'm setting up a multi-page jquery mobile page based on the provided template: http://jquerymobile.com/demos/1.1.1/docs/pages/multipage-template.html
How can I get the header/footer to repeat on all the pages without duplicating it in the page content.
Is there a jquery script for this or do I have to use some kind of php include file?
Thanks in advance!
As far as I know, you must include a header and footer within each
data-role="page"
container. If you wan't to avoid typing this out for each page, then I wouldrequire_once()
a page in PHP that includes the header or footer, and use that in place of writing out a header and footer each time.Sample:
header.php:
footer.php:
Why more JS ?? ... instead of adding two elements for header and footer (either "header" and "footer" tags, or divs with appropriate classes, but mandatory with "position: fixed;") - and add padding top and bottom of the pages divs ? ... No JS code needed ... which will improves the performance ... although very little :) ...
You can use JS (jQuery) to make a template and append it to each
data-role="page"
element as it's being created.Here is a demo: http://jsfiddle.net/vmMVj/
This will append a fixed header to every page as it is being created. I added support for passing a unique title by adding a
data-title="Some Title"
attribute to thedata-role="page"
element.Note that I chose the
pagecreate
event because it occurs when the pseudo-page is about to be initialized. If you were to bind to thepageinit
event, you'd be too late and have to initialize the header widget manually.