You can pass the required data/context for specific pages by specifying all pages data in template7Data parameter sent on initializing an App as shown below −
// Initialize your app var myApp = new Framework7 ({ animateNavBackIcon: true, // Enable templates auto precompilation precompileTemplates: true, // Enabled rendering pages using Template7 template7Pages: true, // Specify Template7 data for pages template7Data: { 'url:likes.html': { likes: [ { title: 'Nelson Mandela', description: 'Champion of Freedom' }, { title: 'Srinivasa Ramanujan', description: 'The Man Who Knew Infinity' }, { title: 'James Cameron', description: 'Famous Filmmaker' } ] }, // Will be applied for page/template with data-page = "contacts" 'page:contacts': { tel: '+1-541-754-3010', email: 'william@root.com', country: 'Canada', }, // Just plain data object which can be passed for other pages using //data-context-name attribute cars: [ { brand: 'Audi', model: 'Q73', fuel_type: 'Diesel', top_speed: 234, seating: 7, color: 'white', price: 54800, }, { brand: 'Porsche', model: 'Cayen', fuel_type: 'Diesel', top_speed: 230, seating: 5, color: 'black', price: 84800, }, { brand: 'BMW', model: 'X6', fuel_type: 'Diesel', top_speed: 270, seating: 5, color: 'blue', price: 54400, }, { brand: 'Toyota', model: 's3', fuel_type: 'Diesel', top_speed: 204, seating: 7, color: 'white', price: 45800, }, ], about: { firstname: 'William ', lastname: 'Root', age: 27, position: 'Developer', company: 'TechShell', } } }); // Add main View var mainView = myApp.addView('.view-main', { // Enable dynamic Navbar dynamicNavbar: true });
You can access and modify any template7Data data in any moment. The template7Data is accessible in global object Template7.data or in its alias myApp.template7Data.
The page and url rules are explained briefly below −
When you specify the property name starting from url: then, this context will be used for the page.
When you specify the property name starting from page: then, this context will be used with specified name of the page.
It is suggested to use url: as it provides accurate detection. However, in some cases, it is impossible to use url:, for instance, in pages with URLs having distinct GET parameters (like contact.html?id = 1 and contact.html?id = 2) or for dynamic pages. In such a case use the page: rule.
The plain data objects provide a way to handle your pages data in more complex and customizable manner. These objects allow you to pass custom context to loaded page by using links and data-context-name attribute.