When enabling a page list template for Magic Data, the basic principle is the same as with Magic Data enabling any block template. Load a Magic Data helper and apply it to the content.
However, in a page list we can provide more flexibility by applying Magic Data to each individual page in the list in turn.
Magic Data has a special provision so that each item in a page list can adapt to the page being listed. To do this you need to include the Original Page Tracker model provided by Magic Data and set it for each page in turn. The generic structure of a Magic Data enabled page list is as follows:
$mdsh = Loader::helper('magic_data_symbols', 'my_package_name');
Loader::model('magic_data/orig_page_tracker', 'jl_magic_data');
$olpt = new MagicDataOrigPageTracker('pagelist');
// then for each page in the list
foreach ($pages as $page){
$olpt->note($page);
$item = // whatever your page list does to get the content of an item
$item = $mdsh -> fill($item);
// whatever your page list does to show an item
}
$olpt->clear();
At the end of the list, calling clear()
will make sure there is no residual value left in the tracker that could confuse things for subsequent uses of Magic Data.
Page lists vary greatly in how they display individual items. Sometimes it is the page description. With Page List Teasers it is actual page content. Other page lists use attributes and/or images in many variations. All of these could in turn contain Magic Data tokens.
The identity of each page in this list is now available to such list items through the symbol ORIGINAL_PAGE.
You can see this code in action in the page list templates provided by Magic Data Templates1.
If this is a template for your own site, you know that Magic Data is already installed. For a Marketplace template, you will also want to guard against the possibility that a site installing the template does not have Magic Data installed. Here you have various options that can be applied individually or collectively:
- Refuse to render the page list if Magic Data is not installed.
- Render a non-magic version of the page list if Magic Data is not installed.
- Show a warning in edit mode if Magic Data is not installed.
- Show a warning when the page is viewed in Magic Data is not installed.
Which you choose is very much a matter of personal choice. For the templates in Magic Data Templates1 I have included code to provide a warning in edit mode and then show the list items without the magic, a combination of 2 and 3 above.
Using the above structure for a Magic Data enabled page list, here are a couple of ideas of what you could do:
Create a page list template that outputs the content of each 'item' by repeating a single text area attribute of the page the page list is on. Within that attribute, write text that includes Magic Data expressions to pull in information about the listed page.
Create a page list template that outputs the content of each 'item' by repeating the same stack. Within that stack, write text that includes Magic Data expressions to pull in information about the listed page.
This technique is not limited to pages. You could do similar for a list of users or for a list of products. In the case of listing products, Magic Data Commerce already provides a Current Product Tracker model for tracking the product within each item of a product list and the CURRENT_PRODUCT symbol relates a product to this.
For a list of users, you would need to create your own model to track the user and provide a symbol to read that back.
All of the above and more is already built into the Uber List addon.