Writing your own Sitemap extension


We use a commandline script for generating the sitemap contents of a project. We provide you with some standard sitemap features for generation in that script, e.g. generating sitemap for all nodes, products, categories, etc. But there might be cases where this provides not enough flexibility for your project so there is the need to write your own extension.

Extension interface

All our extensions need to follow the interface which is defined in Frontastic\Catwalk\FrontendBundle\Domain\SitemapExtension (paas/catwalk/src/php/FrontendBundle/Domain/SitemapExtension.php).

The name is important to determine what you will generate by that extension and will be used inside the filename of the sitemap xml-file.

getEntries() will return the needed urls that should be added to your sitemap. It may also contain an array of image-urls that should be added to the sitemap url-reference as well.

The generation of the sitemap will then take place in our Sitemap generation command. You will need to register it in order to let the command know that there is an extension that should be executed.the

Registering your extension

You need to register your extension so that our command knows which extensions should be executed. This is done by adding a tag to the corresponding service inside the services.xml:

<!-- [...] -->

    <service id="..." class="...">
        <argument type="...">
        <!-- [...] -->
        <tag name="frontend.sitemapExtension"/>

<!-- [...] -->

⚠️ You also need to run the script with the --with-extensions parameter. Otherwise extensions will not be executed!

Adding cronjob for sitemap generation

In order to get this executed regularly you will need to add an entry to the crontab for this. The crontab could be added or found inside the project's config-directory: config/crontab.

There you need to add an entry for the sitemap generation command and adjust it to your needs. For example it may look like this:

29 */2 * * * php bin/console frontastic:sitemap:generate --exclude "^/development" --with-nodes --with-products --with-categories --with-extensions public/sitemaps