PHP code example of itech-world / sulu-article-twig-extension-filter-bundle
1. Go to this page and download the library: Download itech-world/sulu-article-twig-extension-filter-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
itech-world / sulu-article-twig-extension-filter-bundle example snippets
return [
// ...
ItechWorld\SuluArticleTwigExtensionFilterBundle\ItechWorldSuluArticleTwigExtensionFilterBundle::class => true,
];
declare(strict_types = 1);
namespace App\Controller\Front;
use ItechWorld\SuluArticleTwigExtensionFilterBundle\Service\ArticleService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
class ArticleController extends AbstractController
{
public function __construct(
private ArticleService $articleService
) {
}
/**
* API AJAX to load more articles with pagination.
*
* @param Request $request
* @return JsonResponse
*/
#[Route('/api/articles/load-more', name: 'api_articles_load_more', methods: ['GET'])]
public function loadMore(Request $request): JsonResponse
{
$offset = (int)$request->query->get('offset', 0);
$limit = (int)$request->query->get('limit', 12);
$templateType = $request->query->get('type', 'project');
$locale = $request->query->get('locale', $request->getLocale());
try {
$result = $this->articleService->loadRecentPaginated(
$limit,
$offset,
[$templateType],
$locale
);
// Render the HTML of articles
$articlesHtml = '';
if (!empty($result['articles'])) {
$articlesHtml = $this->renderView('articles_cards.html.twig', [
'articles' => $result['articles']
]);
}
return new JsonResponse([
'success' => true,
'html' => $articlesHtml,
'pagination' => $result['pagination'],
'articlesCount' => count($result['articles'])
]);
} catch (\Exception $e) {
return new JsonResponse([
'success' => false,
'error' => $e->getMessage()
], 500);
}
}
}