eZ Publish 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 eZ Publish Public API.
It can also be called directly by its direct URI :
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...).
Important note regarding visibility
Location visibility flag, which you can change with hide/unhide in admin, is not permission based and thus acts as a simple potential filter. It is not meant to restrict access to content.
If you need to restrict access to a given content, use Sections or Object states, which are permission based.
To display a content, the ViewController uses a view manager which selects the appropriate template depending on matching rules.
Content view template
A content view template is like any other template, with several specific aspects.
|eZ\Publish\Core\Repository\Values\Content\Location||The location object. Contains meta information on the content (ContentInfo)|
(only when accessing a location)
|eZ\Publish\Core\Repository\Values\Content\Content||The content object, containing all fields and version information (VersionInfo)|
|Boolean||If true, indicates if the content/location is to be displayed without any pagelayout (i.e. AJAX, sub-requests...).|
|String||The base layout template to use when the view is requested to be generated outside of the pagelayout (when |
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.
Making links to other locations
Linking to other locations is fairly easy and is done with native
path() Twig helper (or
url() if you want to generate absolute URLs). You just have to pass it the Location object and
path() will generate the URLAlias for you.
If you don't have the Location object, but only its ID, you can generate the URLAlias the following way:
Under the hood
In the backend,
path() uses the Router to generate links.
This makes also easy to generate links from PHP, via the
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
This controller is exactly the same as the ViewController presented above and has 2 main actions:
viewLocationto render a location (same as when accessing a content through an URLAlias)
viewContentto render a content
You can use this controller from templates with the following syntax:
The example above allows you to render a Location which ID is 123, with the view type line.
ez_content controller follow the syntax of controllers as a service, as explained in Symfony documentation.
As any controller, you can pass arguments to
ez_content:viewContent to fit your needs.
|Id of the location you want to render.|
Id of the content you want to render.
The view type you want to render your content/location in.
Example: full, line, my_custom_view, ...
Indicates if the sub-view needs to use the main layout (see available variables in a view template)
Hash of variables you want to inject to sub-template, key being the exposed variable name.
Available as of eZ Publish 5.1
Just as for regular Symfony controllers, you can take advantage of ESI and use different cache levels:
Symfony also supports asynchronous content rendering with the help of hinclude.js library.