My php skills are highly limited, but I’ve built a simple plugin that grabs weather data from one site and displays it in an EE template on another site. The plugin works fine as raw php, and it works fine on a blank EE template.
But when I put the tags between a template header and footer, the output displays above the header rather than underneath it.
I’ve looked at other plugins for a clue as to what’s causing this, but without success. Can anyone offer a suggestion?
[Mod Edit: Moved to the Development and Programming forum]
Thanks for the reply, HD. I’m actually using neither one, but you’re close to the problem. The plugin uses curl to get the data. When I originally had $this->return_data = ‘your content’ I ended up with a resource error. When I removed it, the error went away and the content displayed fine. But even with it in there, I still end up with the data displaying above the header.
I assume that by following the API tutorial and having this:
var $return_data = "";And having the curl statements within double quotes was creating the resource error. But every attempt to find a better way didn’t seem to help. Any thoughts on a way to have curl work within return_data?
Like I said, my php is limited…
Sure thing. The EE template tags are:
{exp:Weather3} zip code {/exp:Weather3}
Here is the main part of the plugin:
class Weather3
{
var $return_data;
function Weather3()
{
global $TMPL;
$tagdata = $TMPL->tagdata;
$tagdata = trim($tagdata);
$tagdata = str_replace('\n','', $tagdata);
$tagdata = str_replace('\r','', $tagdata);
$tagdata = str_replace('\t','', $tagdata);
$tagdata = str_replace('\x0B','', $tagdata);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://www.mysite.com/weather_script_path&zipcode;=".$tagdata."");
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}It pulls a three-day weather forecast from a weather database I installed on one site and displays it on a partner’s Web site.
Try this..
Note I haven’t actually tested this, I’m just going from memory…
{exp:Weather3 zip_code="12345"}class Weather3
{
var $return_data = '';
function Weather3()
{
// get a reference to the ee super object
$this->ee =& get_instance();
// get parameters from the template (seems more logical than using tag data)
$zip_code = (int)$this->ee->TMPL->fetch_param('zip_code');
// do curl to weather service
$ch = curl_init();
// note the EE forum seems to put an extra semicolon in the middle of this line
curl_setopt ($ch, CURLOPT_URL, 'http://www.mysite.com/weather_script_path&zipcode;='.$zip_code);
curl_setopt($ch, CURLOPT_USERAGENT, 'MozillaXYZ/1.0');
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch)
curl_close($ch)
// save the output to this variable
$this->return_data = $output;
}
}😊
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.