PDA

View Full Version : Load different TPL files if option selected



Ivan Stefanov
August 30, 2013, 07:19 AM
Hello. I create different maps for each city in advanced search.

How to make in Smarty code to include tpl file with map.

I have a dropdown with cities and maps for all cities.

I want when select New York to include tpl file with map of New York city.

Thanks for help.

Mike
September 2, 2013, 11:31 AM
To load tpl file on dropdown change you need xajax function which will do this.

You can do xajax function based on other functions in the script. there are just few mandatory things to make it working properly

1. Create function somewhere in the class file. for example in the rlCategories.class.php



function ajaxLoadMap( $city )
{
global $_response;


$file = 'maps'.RL_DS.$city.".tpl";

//if you have sub-divisions on your city maps you probably have to prepare them
// $GLOBALS['rlSmarty'] -> assign('locations', $locations);


$_response -> assign("map_container_id", 'innerHTML', $GLOBALS['rlSmarty'] -> fetch( $file, null, null, false ));//all magic in this line

return $_response;
}


2. Register function in the place you need it. if you want your maps on home page only than right place is controllers/home.inc.php



$rlXajax -> registerFunction( array( 'loadMap', $rlCategories, 'ajaxLoadMap' ) );




3. use it in the javascript like below



$('#your_dropdown').change(function(){
xajax_loadMap( $(this).val() );
});



It's not ready instruction and just some detailed thoughts about xajax and how this can be done.