Message-ID: <524453939.4366.1485866294307.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_4365_485285985.1485866294307" ------=_Part_4365_485285985.1485866294307 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Legacy template fallback

Legacy template fallback

The following does not apply to siteaccesses configured with legac= y_mode: true

 

When the standard view provider is not able to select an appropriate tem= plate for a given content, the system fallbacks to the legacy kerne= l and delegates the view selection to itThis ensures that a content is always d= isplayed and hence eases project migration from eZ Publish v4.x to v5.x

=20 =20

Pagelayout and mai= n block

When falling back to the legacy kernel, the old content/vi= ew module is run to return the appropriate view for the giv= en content. However, the pagelayout is not rendered as it needs to be still= rendered by Twig in the Symfony part, for consistency. In this regard, the= system uses the Decorator design pattern to include the g= enerated view in your layout.

For this to work, you need to configure 2 things :

  1. Which template you want to use as a base template for legacy fallback
  2. The name of the block to use in your layout

Base layout f= or legacy fallback

You can configure this by setting the ezpublish_legac= y.<siteaccess_or_siteaccess_group>.view_default_layout config key.

Example:

ezpublish/config/ezpublish.yml
=20
parameters:
    # eZ Publish 5.1+ only
    ezpublish_legacy.my_siteaccess.view_default_layout: AcmeDemoBundle::my_=
layout.html.twig
=20

Block name

Internally when rendering the view coming from the legacy kernel, a Twig= template is created on the fly. This template extends the pagelayout you c= onfigured and includes the content inside a block. The name of this block i= s configurable as well (default is content).<= /p>

ezpublish/config/ezpublish.yml
=20
parameters:
    ezpublish_legacy.<siteaccess_or_siteaccess_group>.view_default_la=
yout: AcmeDemoBundle::my_layout.html.twig
    ezpublish.content_view.content_block_name: content
=20
my_layout.html.twig
=20
<!DOCTYPE html>
<html>
<head>
    <!-- ... -->
</head>
<body>
    {% block content %}{# Content will be inserted here #}{% endblock %}
</body>
</html>
=20

 

Module layout

Version compatibility

The module layout setting is available from eZ Publish 5.1.

The module layout= can also be defined the same way as the base layout, by setting the <= /span>ezpubl= ish_legacy.<scope>.module_default_layout config key. This layout is use= d to handle "non content" related legacy requests.

Displaying l= egacy module result

This makes your base layout reusable. However, content generated by lega= cy modules (i.e. /ezinfo/about) will not be automatically inse= rted as your layout will be rendered as a regular template, receiving module_result variable coming from the legacy kernel. The solution = is to use 2 different templates, one for the global layout, and another for= legacy module rendering:

AcmeDemoBundle::layout.html.twig
=20
<!DOCTYPE html>
<html>
<head>
    <!-- Insert everything you need here that is common -->
</head>
<body>
    {% block content %}{# Regular content will be inserted here #}{% endblo=
ck %}
</body>
</html>
=20
AcmeDemoBundle::layout_legacy.html.twig
=20
{% extends "AcmeDemoBundle::layout.html.twig" %}
 
{% block content %}
    {# module_result variable is received from the legacy controller. #}
    {# It holds the legacy module result #}
    {{ module_result.content|raw }}
{% endblock %}
=20
ezpublish/config/ezpublish.yml
=20
parameters:
    ezpublish_legacy.my_siteaccess.module_default_layout: AcmeDemoBundle::l=
ayout_legacy.html.twig
    ezpublish_legacy.my_siteaccess.view_default_layout: AcmeDemoBundle::lay=
out.html.twig
=20

 

Persistent variable

The persistent variable is a special variable in legacy templates that y= ou can set in order to pass values from the content template to the pagelay= out. This variable, among others, is accessible from the configured Twig pa= gelayout thanks to the helper ezpublish.legacy.

Actually, all data contained in $module_result in the legacy kernel is exposed.

Access to the persistent variable
=20
<!DOCTYPE html>
<html>
<head>
    <!-- ... -->
    {% if ezpublish.legacy.has( 'content_info' ) %}
        {% set persistent_variable =3D ezpublish.legacy.get( 'content_info'=
 )['persistent_variable'] %}
    {% endif %}
</head>
<body>
    {% block content %}{# Content will be inserted here #}{% endblock %}
</body>
</html>
=20

Assets

Like the persistent variable, it is possible to require css and/or javas= cripts assets from a content template through the legacy ezscript_req= uire() and ezcss_require() template operators.

You can easily retrieve those requested assets from the legacy template = in the Twig pagelayout with the ezpublish.legacy helper.

Getting assets requested from a legacy template
=20
<!DOCTYPE html>
<html>
<head>
    <!-- ... -->
    {% set requested_css_files =3D ezpublish.legacy.get( 'css_files' ) %}
    {% set requested_js_files =3D ezpublish.legacy.get( 'js_files' ) %}
 
    {# "configured" assets are the ones defined in design.ini (FrontendCSSF=
ileList/FrontendJavaScriptList) #}
    {% set configured_js_files =3D ezpublish.legacy.get( 'js_files_configur=
ed' ) %}
    {% set configured_css_files =3D ezpublish.legacy.get( 'css_files_config=
ured' ) %}
</head>
<body>
    {% block content %}{# Content will be inserted here #}{% endblock %}
</body>
</html>
=20

Assetic incompatibility

------=_Part_4365_485285985.1485866294307--