Help with Extenison Widget #135
-
Hey, I would like to get data from an API myself using the Extension Widget. However, I have little knowledge of programming and don't really understand the documentation. Can someone explain this to me using a simple example? As a very stupid example, maybe I could realize that I can display all the first three teams (teamName) based with associated icon (teamIconUrl) on this request URL. It doesn't make any sense, I'd just like to understand how it works. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hey, The extension widget is very much intended to be used by people with some programming knowledge. If you are comfortable with / can figure out how to setup a server with PHP, you can use this code which will achieve (albeit naively) your desired result: <?php
$body = file_get_contents('https://api.openligadb.de/getavailableteams/bl1/2024');
$json = json_decode($body, true);
$teams = array_slice($json, 0, 3);
header('Widget-Title: Teams');
header('Widget-Content-Type: html');
?>
<ul class="list list-gap-20">
<? foreach($teams as $team): ?>
<li class="flex gap-15 items-center">
<img style="width: 35px; height: 35px;" src="<?= $team['teamIconUrl'] ?>" />
<div>
<div class="color-highlight"><?= $team['teamName'] ?></div>
<div><?= $team['shortName'] ?></div>
</div>
</li>
<? endforeach; ?>
</ul> |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply. I understand that so far, but what should the widget itself look like? - type: extension
url: https://domain.com/widget/phpfile.php
allow-potentially-dangerous-html: true And the parameters that you can set in the widget are only there to pass variables to my PHP script? I don't understand the meaning of the parameters, I could write the values of the variables directly into the PHP script or not? |
Beta Was this translation helpful? Give feedback.
-
Yup, that looks correct. The parameters are completely optional and are only there for convenience, you don't need to use them and can do everything within the PHP script. They are useful if you want to reuse the same script with different parameters, for example if you modify the top part of the script to this: <?php
$year = $_GET['year'] ?? '2024';
$teamsLimit = $_GET['teams-limit'] ?? 3;
$body = file_get_contents('https://api.openligadb.de/getavailableteams/bl1/' . $year);
$json = json_decode($body, true);
$teams = array_slice($json, 0, $teamsLimit);
header('Widget-Title: Teams ' . $year);
header('Widget-Content-Type: html');
?> You can now reuse the extension and have it display different information without needing to have a slightly different version of the script: - type: extension
url: https://domain.com/widget/phpfile.php
allow-potentially-dangerous-html: true
- type: extension
url: https://domain.com/widget/phpfile.php
allow-potentially-dangerous-html: true
parameters:
year: 2023
teams-limit: 5 |
Beta Was this translation helpful? Give feedback.
-
Ah, great :) Now I understand, thank you :) |
Beta Was this translation helpful? Give feedback.
Yup, that looks correct. The parameters are completely optional and are only there for convenience, you don't need to use them and can do everything within the PHP script. They are useful if you want to reuse the same script with different parameters, for example if you modify the top part of the script to this:
You can now reuse the extension and have it display dif…