Is there a secret to getting a EE template to function as a PHP file? I have a map that is loading the data from a php file. I want to load the data from an EE template instead. I have set the template to allow PHP and have tried input and output but no matter what I try it will not work like I expect when I call it from a js script.

When I use a regular php file the map data loads fine. But if I try to use a EE php template the data will not load

The php file and EE php file have the exact same data

Loading a standard php file works fine : loadData("/assets/external/data.php"); But when I take the exact same code and place it into a EE tempalte with php enabled it does nothing: loadData("http://www.domain.com/index.php/map-data");

my data.php file looks like this:


echo json_encode(
    $data = array(
            'id' => 1,
            'latitude' => 44.5370218, 
            'longitude' => -63.6546377,
            'featured' => 1,
            'title' => " Restaurant",
            'location' => "123 Birch Street",

... etc

but if I copy paste the contents of that php file into an EE template and update the source for loaddata to call it from the template it comes up with nothing to display on my map.

The map page (that shows the actual map with data) uses a javascript. In that js file it pulls the data from data.php

I want that js file to pull the data from a php enabled EE template instead.

Here is a snippet of my JS file:

  if( optimizedDatabaseLoading == 1 ){
            google.maps.event.addListener(map, 'idle', function(){
                if( searchClicked != 1 ){
                    var ajaxData = {
                        optimized_loading: 1,
                        north_east_lat: map.getBounds().getNorthEast().lat(),
                        north_east_lng: map.getBounds().getNorthEast().lng(),
                        south_west_lat: map.getBounds().getSouthWest().lat(),
                        south_west_lng: map.getBounds().getSouthWest().lng()
                    if( markerCluster != undefined ){
                    //loadData("/assets/external/data.php", ajaxData);
                    loadData("http://www.physiotherapyns.ca/index.php/2017-map/map-data/", ajaxData);


to highlight the relevant parts in the js file:

//  THIS WORKS  //
loadData("/assets/external/data.php", ajaxData);

// this does not//  
loadData("http://www.domain.com/index.php/2017-map/map-data/", ajaxData);

both the file and the template contain the exact same data.

Is there anything special about the formatting of an EE template to function as a regular php file?

  • 1
    Could you expand with an example of what you are trying? Are you trying to use require or include in a template to pull in another PHP file?
    – jrothafer
    Commented Mar 8, 2017 at 18:40
  • Ok I will do my best. I have standard EE template that has a google map. To populate the map on that EE template it uses a php file. If I use a regular data.php file the map populates. Now if I take the exact php file and paste it into a EE template no data is populated. Commented Mar 8, 2017 at 20:21
  • 1
    What happens when you visit your data source template directly? Post the results of curl http://www.domain.com/index.php/2017-map/map-data/
    – jrothafer
    Commented Mar 9, 2017 at 15:00
  • page is blank when viewed directly. Not sure how to post results of cURL I tried this php.net/manual/en/function.curl-exec.php but still a blank page Commented Mar 10, 2017 at 12:45
  • 1
    OMG problem solved (I think) simply missing a closing ?> face palm.. Commented Mar 10, 2017 at 15:50


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.