eZ Community » Forums » eZ Publish 5 Platform » Twig templates in admin content preview
expandshrink

Twig templates in admin content preview

Twig templates in admin content preview

Thursday 28 November 2013 9:41:14 am - 10 replies

Hi,

I'm building a site using eZ Publish Community Project 2013.9. For the user frontend, I'm relying completly on the symfony stack - i.e., all templates were implemented using Twig.

Unfortunately, the "Preview" function in the admin backend is still rendering the content through the legacy stack. Therefore this preview is not of much use...

Is there a way to let eZ Publish render the preview using the Twig templates?

Thursday 28 November 2013 10:49:42 am

Hi Markus,

 

yes there is. same way we roughly intend to solve it for next 5.x release.

Setup Symfony to take over the url  ( content/versionview/{ObjectID}/{EditVersion}/{LanguageCode}/{FromLanguage} ) and redirect it to a controller similar to the stock content controller in 5.x stack with the difference being selecting a specific version instead, given legacy admin interface uses iframe to front end this should theoretically work.

In reality there probably is a couple of more edge cases and things to take care of then that, but this should already be a big step towards solving the problem without having to change legacy.

 

Best,

André

Monday 02 December 2013 2:15:57 pm

Hi André, thanks for your reply.

I gave it a try, but it seems that I'm missing something...

There are two issues that I'm fighting at the moment:

* Though the custom route works in my user siteaccess, the admin backend just ignores the symfony2 route and still uses the legacy viewcontroller.

* My custom controller is basically a copy of the eZ\Publish\Core\MVC\Symfony\Controller\Content\ViewController class. This class expects injection of a ViewManager object. I've tried adding this to my services.yml:

    my.controller.preview:
        class: My\CustomBundle\Controller\PreviewController
        arguments: [@ezpublish.view_manager]
        parent: ezpublish.controller.base
        scope: request

But (in the user siteaccess) I always get an exception: "Catchable Fatal Error: Argument 1 passed to My\CustomBundle\Controller\PreviewController::__construct() must be an instance of eZ\Publish\Core\MVC\Symfony\View\Manager, none given"

Could you please give me a hint what I'm missing here?

Monday 02 December 2013 3:41:35 pm

Another approach is to call subrequests into symfony from the legacy stack. We've created a legacy template operator for this: 

https://github.com/blendinteractive/blendsubrequest

From an architectural standpoint, this isn't a good solution, but it works well and provides an easy solution until more of the admin is moved to the Symfony stack.

Monday 02 December 2013 4:13:08 pm

Very nice Joe ! Definitely valuable for migration / Forward compatibility!

I think it deserves a blog post happy.gif Emoticon

Monday 02 December 2013 5:29:22 pm

Hi Joe,

this looks pretty good - I'll try this tomorrow. Thank you very much!

Tuesday 03 December 2013 12:58:18 am

Hi Joe,

I've added your extension, but unfortunately I get a "Operator 'render_controller' is not registered" warning. I regenerated the autoloads array, and the operator class is listed there. Is there anything else I need to do?

Modified on Tuesday 03 December 2013 12:58:59 am by Markus Mahner

Tuesday 03 December 2013 9:36:51 am

Hi Markus

Did you activate the extension in settings/override/site.ini.append.php ?

Tuesday 03 December 2013 11:15:26 am

Hi Jérôme,

yes, I did. I even tried moving the entry around (top/bottom of ActiveExtensions[] list), just in case this would change anything. And of course I cleared the caches every now and then.

Tuesday 03 December 2013 12:19:26 pm

Hi Markus, 

I took another look at the code, I'm not sure why it won't work for you. Sounds like you've tried most of this, but as a troubleshooting checklist:

  • The root of the code from the repo should be at ezpublish_legacy/extension/blendsubrequest in your project
  • The ActiveExtensions list in ezpublish_legacy/settings/override/site.ini.append.php should contain ActiveExtensions[]=blendsubrequest
  • Autoloads should be refreshed. From your ezpublish_legacy folder, 'bin/php/ezpgenerateautoloads.php'
  • The legacy cache should be cleared. From your ezpublish_legacy folder, 'bin/php/ezcache.php --clear-all --purge -s <correct siteaccess>'
  • If it's still not showing up, you might try checking the config for typos, and clearing the cache manually by deleting everything in ezpublish_legacy/var/cache/* and ezpublish_legacy/var/<your siteaccess>/cache/*

I hope that helps.

Tuesday 03 December 2013 1:31:09 pm

@Joe: You should add a composer.json and an entry in Packagist for this extension happy.gif Emoticon

Check this out!

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from