Sites
Site locales
A site can be localized with many locales:
The examples below are fragments of cms/sites/<site>/config.yaml. Merge them into a site that already defines at least one host or path; they are not separate complete site definitions. Start with Configure sites for a working local example.
# config.yaml
site:
locales: ['en', 'de']
default_locale: 'en'
Keep in mind that every site's locales must be included together in framework configuration:
YAML
# config/packages/translation.yaml
framework:
default_locale: en
enabled_locales: [ en, de, fr, it, es ]
PHP
<?php
// config/packages/translation.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
return static function (ContainerConfigurator $container): void {
$container->extension('framework', ['default_locale' => 'en', 'enabled_locales' => ['en', 'de', 'fr', 'it', 'es']]);
};
Force https
Symfony provides a https redirect configuration way using SecurityBundle (https://symfony.com/doc/current/security/force_https.html).
SfsCms provides another easy way to configure this redirection for sites:
site:
https_redirect: true
Configure hostnames
site:
hosts:
- { domain: 'example.local' }
Use environment variables
site:
hosts:
- { domain: '%env(WEB_DOMAIN)%' }
Canonical hostname
One of the hosts can be defined as canonical:
site:
hosts:
- { domain: '%env(WEB_DOMAIN)%', canonical: true }
- { domain: 'www.%env(WEB_DOMAIN)%' }
Also, other hosts can be configured as redirections to canonical hostname:
site:
hosts:
- { domain: '%env(WEB_DOMAIN)%', canonical: true }
- { domain: 'www.%env(WEB_DOMAIN)%', redirect_to_canonical: true }
Locale hostnames or paths
Hosts can define a locale to be selected when using it:
site:
hosts:
- { domain: '%env(WEB_DOMAIN)%', locale: 'en' }
- { domain: 'fr.%env(WEB_DOMAIN)%', locale: 'fr' }
Other option is to define locales as paths:
site:
paths:
- { path: '/en/', locale: 'en' }
- { path: '/es/', locale: 'es' }
- { path: '/de/', locale: 'de' }
Error pages
The configuration accepts error_pages, but the CMS site model marks this feature as not implemented. Configure Symfony error templates for application error pages; do not rely on these entries to replace the exception controller.
site:
error_pages:
404:
es: [ '@site/store/error_pages/404.html.twig' ]
en: [ '@site/store/error_pages/404.html.twig' ]
4xx:
es: [ '@site/store/error_pages/4xx.html.twig' ]
en: [ '@site/store/error_pages/4xx.html.twig' ]
5xx:
es: [ '@site/store/error_pages/5xx.html.twig', '/srv/cms/site/store/error_pages/5xx-es.html' ]
en: [ '@site/store/error_pages/5xx.html.twig', '/srv/cms/site/store/error_pages/5xx-en.html' ]
Slash route behaviours
Redirect / route to a specific route depending on the user language
site:
slash_route:
behaviour: 'redirect_to_route_with_user_language'
route: 'home'
Site sitemaps
site:
sitemaps:
default:
url: sitemap.xml
cache_ttl: 300
Allowed content types
As default, "page" contents are included for every configured host.
But it's able to configure additional content types for hosts:
# cms/sites/blog/config.yaml
site:
allowed_content_types: ['page', 'post']
Default site
site:
allowed_content_types: ['page']
locales: ['es', 'en']
default_locale: 'es'
https_redirect: true
paths:
- { path: '/es', locale: 'es' }
- { path: '/en', locale: 'en' }
error_pages:
404:
es: [ '@site/default/error_pages/404.html.twig' ]
en: [ '@site/default/error_pages/404.html.twig' ]
4xx:
es: [ '@site/default/error_pages/4xx.html.twig' ]
en: [ '@site/default/error_pages/4xx.html.twig' ]
5xx:
es: [ '@site/default/error_pages/5xx.html.twig', '/srv/cms/site/default/error_pages/5xx-es.html' ]
en: [ '@site/default/error_pages/5xx.html.twig', '/srv/cms/site/default/error_pages/5xx-en.html' ]
slash_route:
behaviour: 'redirect_to_route_with_user_language'
route: 'home'
Override default site
Every site default configuration can be overridden for the project:
# cms/sites/default/config.yaml
site:
allowed_content_types: ['page', 'product', 'news', 'faq']
Create custom site
SfsCms supports multisite. It's easy adding a new site creating a config file:
# cms/sites/blog/config.yaml
site:
allowed_content_types: ['article']
locales: ['es', 'en']
default_locale: 'es'
https_redirect: true
hosts:
- { domain: 'blog.%env(WEB_DOMAIN)%' }
paths:
- { path: '/es', locale: 'es' }
- { path: '/en', locale: 'en' }
Configuration reference
# Default configuration for sites
site:
# an array containing the identifiers of content types. The special "page" content type must be added if it's needed
allowed_content_types: ['page']
# an array with every locale that the site needs to use
locales: ['es']
# default locale
default_locale: 'es'
# if enabled, redirects http requests to https
https_redirect: true
# redirect to default path if no one is provided
locale_path_redirect_if_empty: true
# an [optional] array with extra configuration
extra: ~
# an [optional] array with configured hosts
hosts:
- { domain: '<required>', locale: false, scheme: 'https', canonical: false, redirect_to_canonical: false }
# an [optional] array with paths
paths:
- { path: '/es', locale: 'es' }
- { path: '/en', locale: 'en' }
error_pages:
404:
es: [ '@site/default/error_pages/404.html.twig' ]
en: [ '@site/default/error_pages/404.html.twig' ]
4xx:
es: [ '@site/default/error_pages/4xx.html.twig' ]
en: [ '@site/default/error_pages/4xx.html.twig' ]
5xx:
es: [ '@site/default/error_pages/5xx.html.twig', '/srv/cms/site/default/error_pages/5xx-es.html' ]
en: [ '@site/default/error_pages/5xx.html.twig', '/srv/cms/site/default/error_pages/5xx-en.html' ]
slash_route:
behaviour: 'redirect_to_route_with_user_language'
route: 'home'
redirect_code: 301
sitemaps:
-
url: ~
default_priority: false
default_changefreq: false
cache_ttl: 300
alternates_locales: true
alternates_sites: true
alternates_include_hreflang: true
sitemaps_index:
url: false
Site context in fragments
Internal and signed ESI fragments carry their site in the _site request
attribute. Site resolution restores the enabled site object and the host/path
configuration for the fragment's locale before rendering. Query parameters on
normal pages do not override their site. An explicit unknown or disabled
fragment site fails instead of selecting another site.
Menu rendering respects an explicitly supplied site; otherwise it uses the
current resolved site. Standalone ESI fragments have a site and locale, but no
originating page request. Invalidate cached fragments and pages after deploying
changes to site-context resolution.
For a complete discovery-resource example, see Sitemaps and robots.txt.