Message-ID: <1547931846.3388.1485852906357.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3387_790987492.1485852906341" ------=_Part_3387_790987492.1485852906341 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html The Page Field Type

The Page Field Type

Deprecated

The Page Field Type has as of first stable releases of eZ Platform 15.12= and eZ Studio 15.12 been deprecated. A replacement called La= ndingPage is provided with eZ Studio and tools for migration are planne= d to be provided together with 16.02/16.04 release. At that point Page Fiel= d Type will not be bundled anymore.

 

=20 =20

Description

With the Page Field Type, in legacy part of "ezflow" extension, editors = can define a layout with multiple z= ones within a single front- or landing-page.

Within each zone, editors create blocks that = contain particular content categories. Specific content can be added to the= se blocks, they are called block items.

This is particularly useful for managing homepages/landing pages.

Name Internal name Expected input Output
Page ezpage N/A eZ\Publish\Core\FieldType\Pa= ge\Parts\Page

Configuration

Warning

Defining a zone layout

A layout is a combination of zones that are placed on a page. The = placement of the zones is defined in a template that is specified as part o= f the layout configuration. You can define as many layouts as you need.

You can define a new layout and enable it in your main YAML configuratio= n:

ezplatform.yml
=20
ezpublish:
    system:
        my_siteaccess:
            ezpage:
                layouts:
                    myLayoutIdentifier:
                        name: "My =C3=BCber cool layout"
                        template: "AcmeDemoBundle:page/zonelayouts:my_templ=
ate.html.twig"
=09=09=09=09enabledLayouts: [myLayoutIdentifier]
=20

Then, when rendering a Page Field Type using myLayoutIdentifi= erResources/views/page/zonelayouts/my_template.html.twi= g from AcmeDemoBundle will be used (see how to use template identifiers in Symfony d= ocumentation).

Tip

You can specify a legacy template in your layout definition.

=20
ezpublish:
    system:
        my_siteaccess:
            ezpage:
                layouts:
                    myLegacyLayout:
                        name: My legacy layout
                        template: "design:zone/my_legacy_template.tpl"
=09=09=09=09enabledLayouts: [myLayoutIdentifier]
=20

However, doing so will defer block display to the legacy templates= as well.

Available blocks

The blocks need to be defined and enabled in the YAML configuration as w= ell:

ezplatform.yml
=20
ezpublish:
    system:
        my_siteaccess:
            ezpage:
                blocks:
                    myBlockIdentifier:
                        name: "My =C3=BCber cool block"
                    myBlockIdentifier2:
                        name: "My =C3=BCber cool block 2"
=09=09=09=09enabledBlocks: [myBlockIdentifier, myBlockIdentifier2]
=20

Block template selection=

Template selection rules are applied only when you render a block with t= he PageController (using ez_page:viewBlock = from templates), see below.

Like you are able to define template selection rules when displaying Loc= ation and Content objects, you can also define rules for blocks, = with dedicated matchers.

Configuration is a hash built in the following way:

ezplatform.yml
=20
ezpublish:
    system:
        my_siteaccess:
            block_view:
                # A simple unique key for your matching ruleset
                my_rule_set:
                    # The template identifier to load, following the Symfon=
y bundle notation for templates
                    template: AcmeTestBundle:block:campaign.html.twig
                    # Hash of matchers to use, with their corresponding val=
ues to match against
                    match:
                        # Key is the matcher "identifier" (class name or se=
rvice identifier)
                        # Value will be passed to the matcher's setMatching=
Config() method.
                        Type: Campaign
                another_rule:
                    template: AcmeTestBundle:block:custom_block.html.twig
                    match:
                        Type: CustomBlock
=20
Tip

You can define your template selection rules in a different configuratio= n file. Read the= cookbook recipe to learn more about it .

Matchers for block_view follow the same behavior than matchers for regular location_view / content_view, except t= hat their relative namespace will be eZ\Publish\Core\MVC\Symfony\View= \BlockViewProvider\Configured\Matcher .

Hence you can combine matchers with AND and OR capabilities (see main= matchers' documentation page).

Available matchers

Identifier Description
Type

Matches the unique block identi= fier defined in the legacy block.ini file (see legacy documentation).

For example wi= th the following configuration in legacy block.ini, it will match against <= code>Manual3Items:

=20
[Manual3Items]
Name=3D3 Column News
=20


View

Matches the view= =E2=80=99s unique identifier defined in the block definition in th= e legacy block.ini (see legacy document= ation).

For example with the following configuration in = legacy block.ini, it will match against 3_items1:=

=20
[Manual3Items]
Name=3D3 Column News
ViewList[]=3D3_items1
=20

When no view is defined, the default value is default.<= /p>


Id\Block Matches against the block ID, as s= tored in ezm_block table
Id\Zone Matches against the zone ID a bloc= k belongs to, as stored in ezm_block table

 

Displaying the Page co= ntent

This section focuses on how to display blocks from zone/layout templates= .

Render of these templates are triggered when using ez_render_field= () helper, like for any other field type.

See field rendering documentation for more i= nformation.

Layout template

Goal of a layout template is to display = zones for the given layout, depending on your layout = configuration.

Variables pa= ssed to the layout template

Variable name Description Type
zones Zone objects for this Page field Array of eZ\Publish\Core\FieldType\Page\Pa= rts\Zone objects
zone_layout The layout identifier (e.g. "2Zone= sLayout1") string
pageService

The PageService object (read mo= re below). 

eZ\Bundle\EzPublishCoreBundl= e\FieldType\Page

Rendering blocks

Each zone contain blocks that hold your content as block items. To render blocks from a layout template, you need to do a sub-request.

Tip

You can use a custom controller to display a block.

However, if you do so, you might need to get access to the PageService. You can get it via the = service container with identifier ezpublish.fieldType.ezpage.pageServ= ice.

Using ez_page= :viewBlock

This controller is responsible of choosing the right template for = your block, depending on = the rules you defined.

You can use this controller from templates with the following synt= ax:

=20
{{ render( controller( "ez_page:viewBlock", {'block': myBlock} ) ) =
}}
=20
Available arguments
Name Description Type Default value
block The block object you want to render eZ\Publish\Core\FieldType\Page\Parts\Block= N/A
params

Hash of variables you want to i= nject to sub-template, key being the exposed variable name.

=20
{{ render(
      controller(=20
          "ez_page:viewBlock",=20
          {
              'block': myBlock,
              'params': { 'some_variable': 'some_value' }
          }
      )
) }}
=20
hash empty
cacheSettings

Hash of cache settings to use b= y the sub-controller (useful if you use ESI or Hinclude strategies).

=20
{{ render_esi(
      controller(=20
          "ez_page:viewBlock",=20
          {
              'block': myBlock,
              'params': { 'some_variable': 'some_value' },
              'cacheSettings': { 'smax-age': 600 }
          }
      )
) }}
=20
hash (accepted keys are max-= age and smax-age) empty


Variables ex= posed to the block template
Variable name Type Description
block eZ\Publish\Core\FieldType\Page\Parts\Block= The block to display
valid_items Array of eZ\Publish\Core\Fie= ldType\Page\Parts Displayable block items
valid_contentinfo_items Array of eZ\Publish\API\Repo= sitory\Values\Content\ContentInfo Displayable block items, as = ContentInfo objects.
pageService (deprecat= ed as of v5.2) eZ\Bundle\EzPublishCoreBundl= e\FieldType\Page\PageService The PageService object (deprecated)

And of course, all the additional variables you injected in the params argume= nt .

valid_items and valid_contentinfo_items variab= les are available as of v5.2 / 2013.11.

Usage of pageService is deprecated as of v5.2 / 201= 3.11.

 

Using pageVie= w:viewBlockById <= /code>

>=3D EZP 5.3.2
<= /span>

You can render Blocks with E= SI strategy in all contexts, ie including using Varnish with the controller= viewBlockById.

 

This feature is available from eZ Platform 5.3.2.

Available arguments
Name Description Type Default value
id The block ID of the block you want to render
= A \eZ\Publish\API\Reposit= ory\Exceptions\NotFoundException will be thrown, if block could not = be found
string N/A
params

Hash of variables you want to i= nject to sub-template, key being the exposed variable name.

=20
{{ render(
      controller(=20
          "ez_page:viewBlockById",=20
          {
              'id': 42,
              'params': { 'some_variable': 'some_value' }
          }
      )
) }}
=20
hash empty
cacheSettings

Hash of cache settings to use b= y the sub-controller (useful if you use ESI or Hinclude strategies).

=20
{{ render_esi(
      controller(=20
          "ez_page:viewBlockById",=20
          {
              'id': 42,
              'params': { 'some_variable': 'some_value' },
              'cacheSettings': { 'smax-age': 600 }
          }
      )
) }}
=20
hash (accepted keys are max-= age and smax-age) empty

 

Rendering Block items

As said above, a block holds your displayable content as bl= ock items which consists of eZ\Publish\Core\FieldT= ype\Page\Parts\Item objects. Among the available pr= operties, you will find contentId and locationId which reference the content/location you want to di= splay. All you have to do then is to render it view ez_content:viewLocation or ez_co= ntent:viewContent (see full example below).

The PageService object

The PageService object (eZ\Bundle\EzPublishCoreBundle\FieldType\Pa= ge\PageService) is a helper giving the possibility to get current zo= ne/block definitions and to retrieve block items.

Main methods

Method name Description Return type
getZoneDefinition() Returns zone definition (all defined zones for t= he current siteaccess) as an array array
getZoneDefinitionByLayout()<= /code> Returns a zone definition for a gi= ven layout. It consists of a configuration array for the given layout. array
getBlockDefinition()<= /td> Returns block definition as an arr= ay array
getBlockDefinitionByIdentifi= er() Returns a block definition for a g= iven block identifier. array
getValidBlockItems()<= /td> Returns valid items (that are to b= e displayed), for a given block. eZ\Publish\Core\FieldType\Pa= ge\Parts\Item[]
getLastValidBlockItem() Returns the last valid item, for a= given block. eZ\Publish\Core\FieldType\Pa= ge\Parts\Item|null
getWaitingBlockItems() Returns queued items (the next to = be displayed), for a given block. eZ\Publish\Core\FieldType\Pa= ge\Parts\Item[]
getArchivedBlockItems() Returns archived items (that were = previously displayed), for a given block. eZ\Publish\Core\FieldType\Pa= ge\Parts\Item[]
getValidBlockItemsAsContentI= nfo() Returns valid block items as conte= nt objects eZ\Publish\API\Repository\Va= lues\Content\ContentInfo[]

Example

2zoneslayout1.html.twig
=20
<h2>Twig Template for 2 zoneslayout1 zone</h2>
<div class=3D"zone-layout-{{ zone_layout|lower }} row">
    <div class=3D"span8">
        <section class=3D"content-view-block">
        {% if zones[0].blocks %}
            {# Rendering blocks with default PageController #}
            {% for block in zones[0].blocks %}
                {{ render( controller( "ez_page:viewBlock", {'block': block=
} ) ) }}
            {% endfor %}
            <div class=3D"block-separator"></div>
        {% endif %}
        </section>
    </div>
    <div class=3D"span4">
        <aside>
            <section class=3D"content-view-block content-view-aside">
            {% if zones[1].blocks %}
                {# Still rendering with default PageController, but passing=
 specific cache value (TTL of 100 seconds) and using ESI #}
                {% for block in zones[1].blocks %}
                    {{ render_esi( controller( "ez_page:viewBlock", {'block=
': block, 'cacheSettings': {'smax-age': 100}} ) ) }}
                {% endfor %}
                <div class=3D"block-separator"></div>
            {% endif %}
            </section>
        </aside>
    </div>
</div>
=20
campaign_block.html.twig
=20
<h3>Twig Template for Campaign Block type</h3>
{% set validContentInfoItems =3D pageService.getValidBlockItemsAsContentInf=
o( block ) %}
{% set validItems =3D pageService.getValidBlockItems( block ) %}
<!-- BLOCK: START -->
<div class=3D"block-type-campaign">
    <div class=3D"campaign">
        <a href=3D"#" class=3D"navig prev" style=3D"opacity:0;"><s=
pan class=3D"hide">&lt;</span></a>
        <a href=3D"#" class=3D"navig next"><span class=3D"hide">=
;&gt;</span></a>
        <ul class=3D"indicator">
            {% for contentInfo in validContentInfoItems %}
                <li><span>{{ contentInfo.name }} (#{{ contentIn=
fo.id }})</span></li>
            {% endfor %}
        </ul>
        <ul class=3D"images">
        {# Rendering valid items with regular view controller, with "block_=
item_campaign" view type #}
        {# Also passing an "image_class" parameter which will be available =
in sub-template. #}
        {% for item in validItems %}
            {{ render(
                controller(
                    'ez_content:viewLocation',
                    {
                        'locationId': item.locationId,
                        'viewType': 'block_item_campaign',
                        'params': {'image_class': 'campaign'}
                    }
                )
            ) }}
        {% endfor %}
        </ul>
    </div>
</div>
<!-- BLOCK: END -->
=20
------=_Part_3387_790987492.1485852906341--