eZ Community » Forums » eZ Publish 5 Platform » Question about dependency Injection...
expandshrink

Question about dependency Injection and template overriding

Question about dependency Injection and template overriding

Friday 05 June 2015 12:56:18 pm - 2 replies

Hi all,

I actually work on an eZ's 5.90.0alpha1 with SF 2.7.

I created a custom content class and his template and I would like displayed it.

 

In my bundle's config folder I added an .yml file with my templating configuration

 system:
    default:
        location_view:
            full:
                custom_article:
                    controller: MyBundle:CustomArticle:showCustomArticle
                    template: "MyBundle:full:custom_article.html.twig"
                    match:
                        Identifier\ContentType: [custom_article]

Then, I added it to my website configuration with dependency injection (like eZDemoBundle)

 public function prepend(ContainerBuilder $container) {
        $configFile = __DIR__ . '/../Resources/config/templating.yml';
        $config = Yaml::parse( file_get_contents( $configFile ) );
        $container->prependExtensionConfig( 'ezpublish', $config );
        $container->addResource( new FileResource( $configFile ) );
    }

My trouble starts now, I can't display my custom class with my own template. Instead of my twig view, I used a generic template which list all my content fields

 <div class="content-view-full">
     <div class="class-custom_article">
         <div class="attribute-header"></div>
         <div class="attribute-author"></div>
         <div class="attribute-image"></div>
         <div class="attribute-content"></div>
         <div class="attribute-resume"></div>
     </div>
 </div>

If I try to override a template rule for a basic content class I've the same problem, my custom rule don't work

 

For me, my trouble is in my config injection, cause if i copy my rules in ezdemo.yml all of them work correctly. There is no error message in my debug toolbar.

 

Does anyone have an idea ?

Modified on Friday 05 June 2015 12:59:23 pm by Patrick P.

Monday 08 June 2015 7:08:41 am

Hello Patrick,

We recently created an example bundle 'BCPageLayoutOverrideTestBundle' to show very clearly and cleanly how to override the demobundle and ezp twig templates.

https://github.com/brookinsconsulting/BCPageLayoutOverrideTestBundle

Our bundle internals can be studied and used as a reference when creating your own template override bundle. Also our commit history is clean and feature specific so you can review our changes commit by commit to better understand (from a feature commit perspective) exactly what changes we made to support each feature we provide within the bundle.

https://github.com/brookinsconsulting/BCPageLayoutOverrideTestBundle/commits/master

For example this commit shows how we introduced a new example to support to overriding content field templates:

https://github.com/brookinsconsulting/BCPageLayoutOverrideTestBundle/commit/e48f57387a3b88c5869300d64e9ff3702eb37a67

 Question: Are you enabling the Bundle Inheritance feature in your bundle? Here is an example:

https://github.com/brookinsconsulting/BCPageLayoutOverrideTestBundle/blob/master/BCPageLayoutOverrideTestBundle.php#L22

I hope this helps!

Cheers,
Heath

Monday 08 June 2015 9:41:45 am

Hello Heath,

I already know this bundle since I used it to override my layout and it perfectly works (In the same time I answer to your question about bundle inheritance by yes).

 

With your demo, I can easily override an existing template.

 

But, I don't know why, I can't create a template for a custom class (which has no default template) in my own bundle.

 

Did I forget some config ? ... I can't understand why I can override my layout template but not a basic custom class template
  

Edit : I solved my trouble. After creating a new bundle, all overrides works. I think I missed to implement my PrependExtensionInterface ...

Modified on Wednesday 17 June 2015 11:14:19 am by Patrick P.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from