Sitemaps
We use a commandline script for generating the sitemap contents of a project. To generate your sitemap regularly, you'll need to add an entry to the crontab for this. The crontab could be added or found inside your project's config-directory: config/crontab
.
There, you'll 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
You can run the command manually in a sandbox to check the sitemaps are properly generated into public/sitemaps
in your project folder.
To check all sitemap generation optional arguments, in the sandbox, run:
<projectDirectory>/bin/console frontastic:sitemap:generate --help
You'll also need to make sure that 2 sitemaps template files exist, the sitemap.xml.twig
in your <project_folder>/templates/Sitemap/
. For example:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
{% for url in urls %}
<url>
<loc>{% if url.uri matches '(^https?://)' %}{{ url.uri }}{% else %}{{ _publicUrl }}{{ url.uri }}{% endif %}</loc>
{% if url.changed is not null %}
<lastmod>{{ url.changed|date('Y-m-d') }}</lastmod>
{% endif %}
{% if url.images is defined %}
{% for image in url.images %}
<image:image>
<image:loc>{% if image matches '(^https?://)' %}{{ image }}{% else %}{{ _publicUrl }}{{ image }}{% endif %}</image:loc>
</image:image>
{% endfor %}
{% endif %}
</url>
{% endfor %}
</urlset>
As well as your index.xml.twig
in your <project_folder>/templates/Sitemap/
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for sitemap in sitemaps %}
<sitemap>
<loc>{{ _publicUrl }}/{{ sitemap.uri }}</loc>
<lastmod>{{ sitemap.changed|date('Y-m-d') }}</lastmod>
</sitemap>
{% endfor %}
</sitemapindex>
To use the new database sitemap feature (see the changes to sitemaps changelog for more information) you need to have the below variable in your environment
file.
database_sitemaps=1
If you want to extend your sitemap, see the Custom sitemap extension article for more information.
Updated 12 months ago