phpsymfonytwigezpublishezplatform

multisite eZ Platform installation


I'm building a multisite eZ Platforme installation and I need to specify a main layout for my templates. Right now I have a template article.html.twig :

{% extends "main_layout.html.twig" %}

{% block content %}
    <h1>{{ ez_render_field(content, 'body') }}</h1>
{% endblock %}

what I want to do is something like this :

 {% if(siteaccess = "site1"){
        extends "site1_main_layout.html.twig"
  }
 else if(siteaccess = "site2"){
        extends "site1_main_layout.html.twig" 
  }
 %}

Please help me!


Solution

  • You can just configure the layout in the config:

    ezpublish:
        system:
            site1:
                pagelayout: "tpl1.html.twig"
            site2:
                pagelayout: "tpl2.html.twig"
    

    After that, you can just use the following in your full view:

    {% extends pagelayout %}
    
    {% block content %}
        ...
    {% endblock %}
    

    pagelayout is a variable prepopulated by eZ Platform from the above config based on current siteaccess. It requires eZ Platform 1.2 at the least, I believe.

    It should also be noted that pagelayout variable is available only in full view templates. Other templates wishing to use the configured pagelayout must use the following:

    {% extends ezpublish.configResolver.parameter('pagelayout') %}