Custom 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, for example, generating sitemap for all nodes, products, categories, and so on. In some cases, it doesn't provide you enough flexibility so you can write your own extension.
To do this, you'll need to define your extension (like all our other extensions) following the interface here:
The name is important to determine what you'll 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 then takes place in our sitemap generation command. You'll need to register it in order to let the command know that there is an extension that should be executed.
Registering your extension
To register your extension so that it can be executed, you need to add a tag to the corresponding service inside the
<!-- [...] --> <service id="..." class="..."> <argument type="..."> <!-- [...] --> <tag name="frontend.sitemapExtension"/> </service> <!-- [...] -->
--with-extensions parameter. Otherwise, extensions won't be executed!
Adding cronjob for sitemap generation
In order to get this executed regularly, you'll need to add an entry to the crontab for this. The crontab could be added or found inside the project's config-directory:
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
‹ Back to article list