hestec/silverstripe-mailchimp

与Mailchimp API连接

安装: 38

依赖项: 0

建议者: 0

安全: 0

类型:hestec-vendormodule

1.0.0 2024-02-13 10:23 UTC

This package is auto-updated.

Last update: 2024-09-13 12:54:49 UTC


README

将来自OpenWeatherMap免费版本的1至5天天气预报添加到您的SilverStripe网站中(https://openweathermap.org/)。此免费版本仅提供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小时预报,更多细节)。