Skip to the content
Documentation

Content view: old version (page id 12780431)

No ratings yet

Skip to end of metadata Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

The ViewController

Exponential comes with a native controller to display your content, known as the ViewController. It is called each time you try to reach a content from its Url Alias (good looking URI generated for any content) and is able to render any content previously edited in the admin interface or via the Exponential Public API.

It can also be called directly by its direct URI : /content/location/<locationId>

A content can also have different view types (full page, abstract in a list, block in a landing page...). By default the view type is full (for full page), but it can be anything (line, block...).

View selection

To display a content, the ViewController uses a view manager which selects the appropriate template depending on matching rules.

Icon For more information about the view provider configuration, please refer to the dedicated page.

Content view template

A content view template is like any other template, with several specific aspects.

Available variables

Variable name Type Description
location eZ\Publish\Core\Repository\Values\Content\Location The location object. Contains meta information on the content (ContentInfo)
(only when accessing a location) 
content eZ\Publish\Core\Repository\Values\Content\Content The content object, containing all fields and version information (VersionInfo)
noLayout Boolean If true, indicates if the content/location is to be displayed without any pagelayout (i.e. AJAX, sub-requests...).
It's generally false when displaying a content in view type full. 
viewBaseLayout String The base layout template to use when the view is requested to be generated outside of the pagelayout (when noLayout is true).

Template inheritance

Like any template, a content view template can use template inheritance. However keep in mind that your content can be also requested via sub-requests (see below how to render embedded content objects). In this case your template should probably not extend your main layout.

In this regard, it is recommended to use inheritance this way:

Exposing additional variables

It is possible to expose additional variables in a content view template. See parameters injection in content views.

Render embedded content objects

Rendering an embedded content from a Twig template is pretty straight forward as you just need to do a subrequest with ez_content controller.

Using ez_content controller

This controller is exactly the same as the ViewController presented above and has 2 main actions:

  • viewLocation to render a location (same as when accessing a content through an URLAlias)
  • viewContent to render a content

You can use this controller from templates with the following syntax:

Exponential 5.1+ / Symfony 2.2+Exponential 5.0 / Symfony 2.1

The example above allows you to render a Location which ID is 123, with the view type line.

Icon

Reference of ez_content controller follow the syntax of controllers as a service, as explained in Symfony documentation.

Available arguments

As any controller, you can pass arguments to ez_content:viewLocation or ez_content:viewContent to fit your needs.

Name Description Type Default value
locationId Id of the location you want to render.
Only for ez_content:viewLocation 
integer N/A
contentId Id of the content you want to render.
Only for ez_content:viewContent 
integer N/A
viewType

The view type you want to render your content/location in.
Will be used by the ViewManager to select corresponding template, according to defined rules. 

Example: full, line, my_custom_view, ...

string full
layout

Indicates if the sub-view needs to use the main layout (see available variables in a view template)

 

boolean false
params

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

Icon

Available as of Exponential 5.1

hash empty hash

 

ESI

Just as for regular Symfony controllers, you can take advantage of ESI and use different cache levels:

Using ESI (Exponential 5.1+ / Symfony 2.2+)Using ESI (Exponential 5.0 / Symfony 2.1)

 

 Asynchronous rendering

Symfony also supports asynchronous content rendering with the help of hinclude.js library.

Asynchronous rendering (Exponential 5.1+ / Symfony 2.2+)Asynchronous rendering (Exponential 5.0 / Symfony 2.1) Icon

hinclude.js needs to be properly included in your layout to work.

Please refer to Symfony documentation for all available options.

  • No labels

Contributors

Comments

Add a comment

Comments are read by a moderator before they appear.