...
Excerpt | ||
---|---|---|
|
Table of Contents
Use case
Usually, you develop your website using one or several custom bundles as this is a best practice. However, dealing with core bundles semantic configuration can be a bit tedious if you maintain it in the main ezpublish/config/ezpublish.yml
configuration file.
...
Code Block | ||||
---|---|---|---|---|
| ||||
<?php namespace Acme\TestBundle\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\Yaml\Yaml; /** * This is the class that loads and manages your bundle configuration * * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} */ class AcmeTestExtension extends Extension implements PrependExtensionInterface { // ... /** * Allow an extension to prepend the extension configurations. * Here we will load our template selection rules. * * @param ContainerBuilder $container */ public function prepend( ContainerBuilder $container ) { // Loading our YAML file containing our template rules $config$configFile = Yaml::parse( __DIR__ . '/../Resources/config/template_rules.yml'; $config = Yaml::parse( file_get_contents( $configFile ) ); // We explicitly prepend loaded configuration for "ezpublish" namespace. // So it will be placed under the "ezpublish" configuration key, like in ezpublish.yml. $container->prependExtensionConfig( 'ezpublish', $config ); $container->addResource( new FileResource( $configFile ) ); } } |
Code Block | ||
---|---|---|
| ||
# We explicitly prepend config for "ezpublish" namespace in service container extension, # so no need to repeat it here system: ezdemo_frontend_group: ezpage: layouts: 2ZonesLayout1: name: "2 zones (layout 1)" template: "AcmeTestBundle:zone:2zoneslayout1.html.twig" location_view: full: article_test: template: "AcmeTestBundle:full:article_test.html.twig" match: Id\Location: 144 another_test: template: "::another_test.html.twig" match: Id\Content: 142 block_view: campaign: template: "AcmeTestBundle:block:campaign.html.twig" match: Type: "Campaign" |
...
Info | ||
---|---|---|
| ||
Service container extensions are called only when the container is being compiled, so there is nothing to worry about regarding performance. |
Note |
---|
In dev environment, each time you modify files loaded this way, you'll need to manually clear the cache as Symfony doesn't check modification time on them. |
Tip |
---|
Tip |
Configuration loaded this way will be overridden by the main |