This site has been archived. To learn more about our current products Ibexa Content, Ibexa Experience, Ibexa Commerce head over to the Ibexa Developer Portal

eZ Community » Blogs » Damien Pobel » Twig pagelayout for legacy modules in...


Twig pagelayout for legacy modules in eZ Publish 5

Wednesday 01 May 2013 1:02:35 pm

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

(For french speaking people, the original french version of this article is available on my own blog)

As I'm currently upgrading the french Planet eZ Publish to the last eZ Publish 5, I'm also reviewing some of the bugs or the missing features I encountered when setting up the eZ Publish 5 version back in december 2012. One of those issues was about the differences between the pages generated by a legacy module (ezinfo/about, planet/search, ...) and the rest of the website. This was due to the fact that in 5.0, it was not possible to use a Twig pagelayout with a legacy module so the result of those modules were still injected in the good old pagealyout.tpl. Starting from the versions 2013.4 and 5.1, it's possible to use a Twig pagelayout on the legacy modules. That's a neat feature for a smooth and progressive upgrade to the new stack, but there are many interesting facts about it.

First, the initial version has been added by Joe Kepley through a pull request, he deserves a big applause for this :-)

Secondly, while working on a related issue, I added the ability to define this pagelayout by siteaccess or siteaccess group. There's currently no semantic configuration for this, so to configure the pagelayout to use for legacy modules in a given siteaccess, you have to write something like this in ezpublish.yml:

  ezpublish_legacy.planete.module_default_layout: PlanetBundle::pagelayout.html.twig

Where planete is the name of a siteaccess or a siteaccess group and the value is a path to the template.

And last, with very few changes, you can use the very same pagelayout as for the rest of the website. The main and possibly only thing to do is to adpat the default content block so that it works with the legacy modules. When the pagelayout is used with a legacy module, the variable module_result is available, so a simple if condition allows to detect the context:

<!DOCTYPE html>
<html lang="fr-FR">
<!-- ... -->
{% block content %}
    {% if module_result %}
        {# we are in a legacy rendered module #}
        {{ module_result.content|raw }}
    {% endif %}
{% endblock %}

Simple, isn't it? This is one of the numerous bridges between eZ Publish legacy and the eZ Publish 5 stack. To learn more, you should really consider attending the eZ UnConference #2, definitively the quickest way to learn everything about eZ Publish 5!

Edit at 2:30pm: this feature is documented and in the documentation the example is using the template inheritance provided by Twig.

Proudly Developed with from