This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » eZ Publish 5 Platform » Best way to use override System in Ez...
expandshrink

Best way to use override System in Ez Publish 5

Best way to use override System in Ez Publish 5

Monday 08 April 2013 12:39:08 pm - 14 replies

Hello,

I am thinking about what is the best way to override files of the new eZ 5 system in a general way.

 

In the old eZ 4 System it was possible to override files from anywhere without modyfying the original files because of the overryide system, where the last file in a list was used to override an other one.

That functionality is exactly what I am trying to use in eZ 5 now.

 

For example, installed eZ 5 with the Demo Site Package. The bundle for this is located under /src/EzSystems/DemoBundle.

Now I want to change a few files like template or controller files. What is the best way to do this?

 

The essencial question is how to extend an bundle in the best way, use all its core files and extending it WITHOUT changing or replacing files of the original bundle. I don't want to use the legacy system override rules, because we are looking forward to the new eZ 5 System depending on symfony.

Further, I would like to replace system files too, without touching them. Is this possible, like in eZ 4?

 

I already read the article

http://share.ez.no/forums/ez-publish-5-platform/overriding-templates-in-ez-5

but it didn't answer my question.

I read the eZ 5 documentation too but didn't find anything that gives me an answer to this question.

 

Thanks for your suggestions.

Modified on Monday 08 April 2013 12:43:01 pm by Christopher Wiebach

Wednesday 10 April 2013 10:26:02 am

I found out different ways to override the templates... but I don't know whats the best way:

 

Way 1: Extend an existing template

Create an own extension -> create a template -> {% extend eZDemoBundle::pagelayout.html.twig %} -> then I could override the different blocks from the pagelayout.html.twig.

 

Way 2: Configure the ViewProvider settings

add some location_view settings into ezpublish.yml for different siteaccesses and create some match rules

 

Way 3: Use the config resolver

first I declare my controller as a service and inject the config resolver service -> Then I can override different settings for different scopes

 

I am new to eZ Publish and don't know what is the best way for doing this. I would like to use the fallback system of eZ 4 in eZ 5 without using the legacy mode too and would like to know which of the 3 ways i described is the best and then how to use fallback settings... do you have an idea?

 

Thanks for any suggestions

Wednesday 11 February 2015 5:25:06 pm

This is a good question.

For Template Overriding with fallback i tried

https://github.com/liip/LiipThemeBundle

With this bundle you can define a themes and you could define also default themes because you can define custom location where symfony should search after template files.

Saturday 14 March 2015 2:13:57 pm

Hi guys. Good questions indeed...

We know that what is offered by Symfony & Twig is clearly not as flexible as what we had with the override system in eZ 4. We have investigated integration of LiipThemeBundle a couple month ago, but unfortunately, it would only cover a small fraction of what we had.

One thing you could do, though, that would I think answer those particular questions, is give Sf2 Bundle Inheritance a try. It allows you to create a Site Bundle that inherits from the DemoBundle, and override parts of it by naming them the same way. Sounds familiar, doesn't it ? It doesn't allow multiple inheritance, and won't cover the most advanced use-cases, but I believe it could help.

Now, about the bigger picture. Which parts of the DemoBundle do you rely on the most ? I'm asking this question because we (Product & Engineering) don't really see the DemoBundle as something people would base their projects on. I'm emphasizing "really" as this is actually a heated debate. I'm kind of leaning against it, as I believe we are trying to make it do too many things. It can't be at the same time a demo of all features, a show-room for best-practices, a living tutorial and a framework for projects happy.gif Emoticon

My concern is that the DemoBundle isn't really something we support in terms of BC... and we'd rather not, as it means more work on something that isn't our core value. Maybe we could discuss your usage of it, and see what could be abstracted in a better way ?

Friday 17 April 2015 12:46:21 am

Hi

I am trying to override the DemoBundle template, and have hit an error. I saw this thread, and went back and checked the recent link to the bundle inheritance and as far as I can tell I have done everything correctly.

I have used the

"php ezpublish/console generate bundle" auto command to create my new bundle and stuck to the default settings as I prefer to use yml. Next I added the "getParent()" to my ...Bundle.php file

 

<?php

namespace Baan\MagpieBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class BaanMagpieBundle extends Bundle
{
    public function getParent()
    {
        return "eZDemoBundle";
    }
}

 

and tried adding pagelayout.html.twig to resources/views in my new bundle, but when I load up the page again, I get the following error message.

 

An exception has been thrown during the rendering of a template ("None of the chained routers were able to generate route: Route 'ezpublish_ezdemo_search' not found"blunk.gif Emoticon in eZDemoBundle::page_header_searchbox.html.twig at line 1.

 

If I take the getParent() away again, the error goes away.

 

 

 

Thanks in advance for any help you can give

 

Barry

Friday 17 April 2015 2:24:49 am

I feel it is wrth mentioning that the eZDemoBundle is in a location where I wasn't expecting it to be.

vendor/ezsystems/demobundle/EzSystems/DemoBundle

 

I was expecting it to be in the src folder as I think I have seen in a couple of tutorials! I don't know if this causes any problems, but it was where it was located in the 2014.11 ezpublish download.

 

 

 

Friday 17 April 2015 6:10:36 am

Hello Barry,

Bundles can be installed in both src or vendor depending on several best practices and various developer choices.

Public bundles installed via composer from packagist.org packages are often installed in vendor instead of src (like the DemoBundle). This by default provides for clean separation from your custom code and everyone else's within the system.

That said, I have recently seen custom composer.json install custom private bundles directly from bitbucket.org into src instead of vendor (ie: no packagist.org packages; not really related).

I like to think of src as a local project playground while vendor is for public bundles and upstream bundle sources.

I think tutorials use src as a reference since it provides guidance which copying / following the tutorial within your own test installation.

Just my uneducated thoughts at this moment. No worries either way.

Cheers,
Heath

Saturday 18 April 2015 10:42:22 pm

Hello Berry,

Your efforts to get started with eZ Publish 5 have inspired me to follow along on my own and try to give better help to you and the rest of the community.

I researched the error you reported above and found it has been addressed in this issue ticket: https://jira.ez.no/browse/EZP-23575

I also took the time to create and test a working custom bundle which successfully overrides the DemoBundle pagelayout.html.twig template using 2014.11.

I have published this minimal custom bundle for everyone with a need to use as a learning resource: 

https://github.com/brookinsconsulting/BCPageLayoutOverrideTestBundle

I hope this helps!

Cheers,
Heath 

Sunday 19 April 2015 4:39:18 pm

Hi Heath

 

Many thanks, that worked!

I had the correct .php file for my new bundle but had missed out some of the includes on the pagelayout.html.twig but yours overrides perfectly.

If anybody else follows this thread, please be aware that you may need to run:

php ezpublish/console assets:install --env=dev

 

after setting the template override. Without it, my debug toolbar would not work.

Barry

Wednesday 22 April 2015 1:03:51 am

Hi. I now have another problem, although I feel it is related to this one.

 

I was able to successfully install Heath's override bundle, and the override text showed on the front page and I am able to add other text and code into html.twig files in my own bundle that override  the eZDemoBundle and everything works

However, when I try to override the css in the same way (adding a css file in resources/views of my own bundle that has the same name as the ones in the same relative position in the eZDemoBundle then the layout of the page changes and elements are thrown out of place. This even happens when only one colour is overriden, eg background-color:black gives a black background, but changes the layout. so does color:red after changing the text the layut is also affected. 

 

I cannot think of a reason for this to happen, but would appreciate any help to get it sorted out.

 

Many thanks

 

Barry

Wednesday 22 April 2015 2:42:37 pm

Hello Barry,

Remember you have to edit the used pagelayout twig template and modify the code to include the stylesheets your additional custom bundle provides. Here is a simple example I tested and used recently:

{% stylesheets filter="compass,cssrewrite"
        "@VendorCustomTagBundle/Resources/public/scss/styles.scss"
        "@BcCustomSiteBundle/Resources/public/scss/styles.scss"
        "bundles/customerdomainnamestring/scss/styles.scss"
    %}

Remember to reinstall assets (as needed)

sudo -u _www php54 -d memory_limit=-1 ezpublish/console assets:install --relative --symlink web
 
sudo -u _www php54 -d memory_limit=-1 ezpublish/console assetic:dump --env=dev web

I hope this helps!

Cheers,
Heath

Wednesday 29 April 2015 1:31:40 am

Hello,

Yes I got everything working here by using Heaths advice and template. If you are looking for a solution to this problem then follow this thread and you will get there.

One thing that I forgot to do at first, however, was to make sure that any css file that you want to override follows the same directory structure as the one you are overriding.

So for example in the eZDemoBundle the main CSS file is Resources/views/css/bootstrap.css

This means that in your own bundle you have to copy the bootstrap.css file to the Resources/viewa/css/ folder of your own bundle before you start replacing the CSS in this new file.

And don't forget to clear the cache and install the assets. I ran

 

php ezpublish/console ca:cl

php ezpublish/console assets:install --env=dev --relative --symlink web

 

but you may need to amend these depending on your needs.

 

Good luck everybody, and thank you to Heath for your amazing help!

Wednesday 06 May 2015 10:07:54 pm

Hi Heath, 

I have a further question on this topic...

I haven't looked into the "platform" version of EZ that has more recently been released and uses Symfony components instead of legacy. Would these same amendments work on the Platform version if I was to upgrade to that, or would it be completely different?

After all, it seems that the Platform version is the future!

 

Thanks

 

Barry

Wednesday 06 May 2015 10:51:35 pm

Hello Berry,

All ezplatform is (at this time) is a legacy free version of eZ Publish, everything else is the exact same.

If your already using new stack only (symfony; no legacy) solutions for user siteaccess development, all of that code will work when used within ezplatform (future compatible).

The problem I have with recommending ezplatform today (while it is still alpha) is that the admin replacement called ezplatformUI (also alpha) is still feature incomplete in many ways, for example it still lacks ContentType creation / editing.

When ezplatformUI is ready for official release (and feature complete) then I will look forward recommending those who wish to go -all new stack- (no legacy at all) to use ezplatform.

Until that day, you loose nothing by using ezpublish 5.x and everything you do within the symfony stack (bundles) is useable within ezplatform (since they share the same kernel).

That said, just remember anything you develop with legacy or within legacy will need to be re-implemented within symfony when you migrate to ezplatform.

If you have the time, you could setup two local dev envs with the same custom bundles and configs and learn how to run both versions (ezplatform and ezpublish 5.x) in parallel to learn more about ezplatform happy.gif Emoticon

I hope this helps!

Cheers,
Heath

Thursday 07 May 2015 11:46:51 pm

Thanks Heath

Thats pretty much how I saw it after reading what I could find.

I am using 5.4 (2011.14) as it is the stable version, but haven't gone into trying to develop anything yet. The next projects that I will be working on can (as far as I can tell) be implemented by using the existing admin features which some frontend design (mainly CSS), so I think I will probably work through these projects and then re-evaluate where Platform is. Since I have a little Symfony experience, it may be that I can then start developing without having to use legacy at all, and just go straight to full-stack / Platform.

It is such a good CMS though, I can see the benefits, and exciting times are ahead!

 

Barry

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from