0

I have three files, a weather.php file which contacts an API and returns weather to my weather.tpl file. However I want to take the contents of the weather.tpl file (which only contains the api response) and post it to another page, any ideas about how I can go about doing this? I'm using smarty version 3.1.33.

Here are my files.

// Weather.php

<?php

$ch = curl_init();
$location = 'MyLocation';
$apikey = 'MyApiKey';
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'http://api.openweathermap.org/data/2.5/weather?q='.$location.'&appid='.$apikey);
$output = curl_exec($ch);
curl_close($ch);//Free up system resource
$output = json_decode($output, true);
echo "The weather in ".$location." for MusicWorks Festival will be ".$output['main']['temp'];
?> 


//weather.tpl

{block name="weather"}

{/block}


//account.tpl (where I want the contents to end up)

<div>
  {block name="weather"}The weather: {/block}
</div>

I have used smarty like this to display both pages.

{extends file="layouts/main.tpl"}

{block name="body"}
CoderHarry
  • 13
  • 6

0 Answers0