hestec / silverstripe-webwinkelkeur
与WebwinkelKeur API连接
Requires
- silverstripe/cms: >=5.0
- silverstripe/framework: >=5.0
- webwinkelkeur/client: 1.*
This package is auto-updated.
Last update: 2024-09-16 16:54:15 UTC
README
使用来自OpenWeatherMap免费版本的天气数据(https://openweathermap.org/)为您的SilverStripe网站添加简单的1至5天天气预报。此免费版本只提供5天/3小时预报,但此模块将收集到的数据转换为1至5天的全天预报。目前它只是一个简单的预报,包含天气图标和最低温度和最高温度。
要求
- SilverStripe 4
- cmfcmf/openweathermap-php-api
版本
使用语义版本控制。
安装
通过Composer安装
composer require "hestec/silverstripe-openweathermap": "1.*"
配置
在https://openweathermap.org/注册(免费)账户并获取您的API密钥。
将OpenWeatherMap API密钥添加到您的yaml文件中
Hestec\OpenWeatherMap\OpenWeatherMapExtension:
ApiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
执行dev/build并刷新。
工作
OpenWeatherMap免费版本(最多5天)的预报数据将存储在OpenWeatherMapData表中,并且当有人访问网站时,每3小时更新一次。这种方法减少了API调用次数,即使OpenWeatherMap服务暂时不可用,也会显示天气。
使用
在您的页面中包含OpenWeatherMap
<% include OpenWeatherMap %>
这提供了一个里约热内卢的5天天气预报。我猜你想要其他城市的预报。为此,将模板\silverstripe-openweathermap\templates\Includes\OpenWeatherMap.ss复制到您的主题的templates\Includes文件夹中,并更改循环调用的参数
<% loop WeatherForecast(5, 3451190) %>
其中数字是预报天数(最多5天)而代码是在OpenWeathetMap上使用的城市代码。在https://openweathermap.org/city上找到您所在城市的代码:搜索城市名称,并在url中找到代码。
或者,只需将此循环放入您的页面中
<% loop WeatherForecast(5, 3451190) %>
<p>$CityName, $CityCountry $Date:<br>
Minimum temperatuur: $TemperatureMin<br>
Maximum temperatuur: $TemperatureMax<br>
<img src="$IconUrl">
</p>
<% end_loop %>
如果您想使用自己的图标而不是标准的OpenWeatherMap图标,请使用$Icon以及您图标的路径。例如
<% loop WeatherForecast(5, 3451190) %>
<p>$CityName, $CityCountry $Date:<br>
Minimum temperatuur: $TemperatureMin<br>
Maximum temperatuur: $TemperatureMax<br>
<img src="/themes/simple/img/weather/$Icon\.png">
</p>
<% end_loop %>
在此处找到所需图标的列表:https://openweathermap.org/weather-conditions
问题
无已知问题。
待办事项
- 制作一个elemental扩展。
- 测试。
- 更多预报类型(3小时预报,更多细节)。