slp_javascript_results_string

slp_javascript_results_string

Default Priority: 10
Parameters:
1. HTML String – the printf format string for formatting the results.
Category: User Interface

The string that is used to create the search results under the map when a user search is performed.   Set your filter to priority 11 or higher to ensure the primary format string is built if you wish to augment it.   Set the priority to 9 or less and remove the slp_javascript_results_string filter to take over the output completely.

This string is used inside of the JavaScript processor that parses and displays the JSONP results.    The string must use the JavaScript format string positional placeholders to display the data elements in the JSONP response.    For example “{0} is {1} {2} away” will show something similar to “Joe’s Bar is 1.2 mi away”.

The parameters and position numbers are:

  • {0} Store Name
  • {1} Distance
  • {2} Distance Unit (mi, km)
  • {3} Street
  • {4} Street 2
  • {5} City/State/Zip
  • {6} Phone
  • {7} Fax
  • {8} Website Link
  • {9} Email Link
  • {10}  The Google Maps URL (typically maps.google.com)
  • {11} Searched (starting) address, Encoded
  • {12} Location address, Encoded
  • {13} The text for “directions” string
  • {14} Tag List
  • {15} The Store ID
  • {16} The Country

Default Format String

Store Locator Plus uses the following default format string as of SLP version 3.7:

                    '<center>' .
                    '<table width="96%" cellpadding="4px" cellspacing="0" id="slp_results_table">'  .
                        '<tr id="slp_location_{15}">'  .
                            '<td id="slp_left_cell_{15}"><span>{0}</span><br/>{1} {2}</td>'  .
                            '<td id="slp_center_cell_{15}">{3}{4}{5}{16}{6}{7}</td>'  .
                            '<td id="slp_right_cell_{15}">{8}{9}'  .
                                '<a href="http://{10}' .
                                '/maps?saddr={11}'  .
                                '&daddr={12}'  .
                                '" target="_blank">{13}</a>{14}</td>'  .
                            '</tr>'  .
                        '</table>'  .
                        '</center>';

Example

In this example  displays the results in a simple list showing the name and distance away with a line underneath that says “get directions”.  Clicking that link will open a new window showing driving directions from the searched address to the location listed.

 // Search Functionality Hook
 //
 add_filter('slp_javascript_results_string',
 array('SLPEnhancedResults','mangle_results_output'),
 90
 );
/**
 * Main SLP Enhanced Results Class
 */
 class SLPEnhancedResults {
/**
 * Method: mangle_results_output
 */
function mangle_results_output($resultString) {
 return preg_replace('/.*/',
 '{0} is {1} {2} away.<br/>' .
 '<a href="http://{10}/maps?saddr={11}&daddr={12}" target="_blank">Get directions.</a>'
 ,
 $resultString);
 }
 }