<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* @Route("/news", priority=10, name="news_")
*/
class NewsController extends AbstractController
{
/**
* @Route("/", name="index")
*/
public function index()
{
/* Get news from api */
$newsJson = ['entries' => []];
try {
$newsJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/news?token=863f1ccdb97de3b924e07b600ce0f5');
if ($newsJsonPath !== false) {
$newsJson = json_decode($newsJsonPath, true) ?: ['entries' => []];
}
} catch (\Exception $e) {
error_log('API Error in NewsController (news): ' . $e->getMessage());
}
/* Get meta from api */
$metaJson = null;
try {
$metaJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/singletons/get/news?token=863f1ccdb97de3b924e07b600ce0f5');
if ($metaJsonPath !== false) {
$metaJson = json_decode($metaJsonPath, true);
}
} catch (\Exception $e) {
error_log('API Error in NewsController (meta): ' . $e->getMessage());
}
// Fallback if API is not available
if ($metaJson === null) {
$metaJson = [
'title' => 'News',
'description' => 'Alle Neuigkeiten rund um den Tennis Club.',
'keywords' => 'Tennis, News, CTC, Rheda'
];
}
return $this->render('pages/news.html.twig', [
// passed data to template
'news' => $newsJson['entries'],
'page' => array(
'title' => 'News',
'description' => 'Alle Neuigkeiten rund um den Tennis Club.',
'meta' => $metaJson
)
]);
}
/**
* @Route("/{slug}", name="detail")
*/
public function detail($slug)
{
/* Get news from api */
$newsJson = ['entries' => []];
try {
$newsJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/news?token=863f1ccdb97de3b924e07b600ce0f5');
if ($newsJsonPath !== false) {
$newsJson = json_decode($newsJsonPath, true) ?: ['entries' => []];
}
} catch (\Exception $e) {
error_log('API Error in NewsController detail (news): ' . $e->getMessage());
}
return $this->render('pages/news-detail.html.twig', [
// passed data to template
'slug' => $slug,
'news' => $newsJson['entries'],
]);
}
}