1. Go to this page and download the library: Download xorgxx/neox-seo-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/ */
use NeoxSeo\NeoxSeoBundle\Attribute\NeoxSitemap;
class PageController extends AbstractController
{
#[Route('/about', name: 'app_about')]
#[NeoxSitemap(priority: 0.8, changefreq: 'monthly')]
public function about(): Response
{
// This page will automatically appear in /sitemap.xml
return $this->render('page/about.html.twig');
}
#[Route('/contact', name: 'app_contact')]
#[NeoxSitemap(priority: 0.6, changefreq: 'yearly')]
public function contact(): Response
{
// This one too
return $this->render('page/contact.html.twig');
}
}
namespace App\Sitemap;
use NeoxSeo\NeoxSeoBundle\Sitemap\SitemapProviderInterface;
use App\Repository\ProductRepository;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class ProductSitemapProvider implements SitemapProviderInterface
{
public function __construct(
private readonly ProductRepository $productRepository,
private readonly UrlGeneratorInterface $urlGenerator,
) {}
public function getUrls(): array
{
$products = $this->productRepository->findAll();
$urls = [];
foreach ($products as $product) {
$urls[] = [
'loc' => $this->urlGenerator->generate('app_product_show', ['id' => $product->getId()], UrlGeneratorInterface::ABSOLUTE_URL),
'lastmod' => $product->getUpdatedAt()->format('Y-m-d'),
'changefreq' => 'weekly',
'priority' => 0.7,
];
}
return $urls;
}
}
// app_produits has #[NeoxBreadcrumb(label: 'Produits')]
// This route would auto-deduct "Produits" as parent, but we don't want a breadcrumb here
#[Route('/produits/api', name: 'app_produits_api')]
#[NeoxBreadcrumb(enabled: false)]
public function api(): Response
{
// No breadcrumb at all on this page — not even "Accueil > Produits"
return $this->json([...]);
}
use NeoxSeo\NeoxSeoBundle\Breadcrumb\BreadcrumbService;
class ProductController extends AbstractController
{
// URL: /produits/{id}
// Breadcrumb: Accueil > Produits > Fond pizza
#[Route('/produits/{id}', name: 'app_product_show')]
public function show(BreadcrumbService $breadcrumb, Product $product): Response
{
// addRoute() = clickable item (generates URL from route name)
$breadcrumb->addRoute('Produits', 'app_produits');
// add() = plain text item (last item, not clickable)
$breadcrumb->add($product->getName());
return $this->render('product/show.html.twig', ['product' => $product]);
}
}
// Route: app_produits_show → /produits/{id}
// Auto-deduction: app_produits_show → app_produits → "Produits"
#[Route('/produits/{id}', name: 'app_produits_show')]
#[NeoxBreadcrumb(label: '')] // label will be overridden by injection
public function show(BreadcrumbService $breadcrumb, Product $product): Response
{
// Parent "Produits" was auto-deduced from app_produits
// Now add the dynamic product name as the last item
$breadcrumb->add($product->getName());
}
#[Route('/', name: 'seo_home')]
public function index(): Response { ... }
#[Route('/contact', name: 'seo_contact')]
public function contact(): Response { ... }