Dialogs Framework Basic Concepts

Implement Phantom Pages

Updated: 21 Apr 2023


Phantom pages allow each item in a list to have its own page and URL without the need to actually create a page each time an item is added.

For example you might have a list called 'MyProducts' with an item called 'Red widget 123'. If you create a phantom page group called 'products' the URL to get to the page about 'Red widget 123' would be www.mysite.com/products/Red_widget_123.html and you wouldn't have to create a special page for it. This is especially handy if you have a list with thousands of items.

Dialogs funnels all phantom page requests to one special page specified in the phantom page group properties. It also populates a special array containing the list item requested: $this->phantom_row So, to display the item_name field of the 'Red Widget 123' from the previous example:

  • $this->phantom_row[item_name]
  • in a list template: <? $this->phantom_row[item_name] ?>
  • in a page template: <?php echo $this->phantom_row[item_name]; ?>
  • in a page automation script: $this->db_page_row['body'] = str_replace('{product_item_name}',$this->phantom_row[item_name],$this->db_page_row['body']);
  1. Create a page in another page group to be displayed whenever a visitor uses a phantom page URL (e.g. /en/products.html) Often this page will call a "detail" list template with Item Detail describing the fields to show. The where clause for this detail template might look like this:
    item_active=1 AND phantom_page='<? $this->phantom_row[phantom_page] ?>'

    IMPLEMENTATION NOTE: if you want a page to show in the nav for pagegroup /en/ (for example) but really display the first phantom page for a phantom pagegroup, create 2 pages:

    1. First Page (green) is a place holder in the nav and redirects to the first phantom page (e.g. /products/product_one.html)
    2. Second Page (yellow) is specified as "Phantoms Real Page" in phantom pagegroup record (see below) and contains the detail list template to show the item detail
  2. Add a field to the list to hold the phantom page name. This is usually 'phantom_page' by convention.
  3. Edit the list's properties and add a 'POST script' AKA 'list automation script' filename. These are by convention the name of the list + .post.inc.php
  4. Edit the skeleton list automation script and add code to populate the new 'phantom_page' field. You don't have to use the item_name field but whatever field you use must be unique or Dialogs won't know which item you mean. here's an example that uses item_name:
    } else {
      $edited_item_row = $this->getOneRowV2('My_List_Name','item_id',$item_id);
      // do something here for inserted or saved items.
      $phantom_name_should_be = preg_replace('/[^a-zA-Z0-9]/','_',$_POST['item_name']) . '.html';
      if($_POST['phantom_page'] != $phantom_name_should_be) {
        $sql = "UPDATE `My_List_Name` SET phantom_page='$phantom_name_should_be' 
            WHERE item_id='" . $item_id . "'";
        $result = $this->query($sql);
      }
    
  5. Create a new page group for the phantom pages:
    1. Select the list in the 'Phantom Page Table' field
    2. Enter 'phantom_page' for 'Phantom Page Field'
    3. Select the page group and page name of the 'real' page for the phantoms.

LinkedInFacebookYouTubeTwitter