Browsing and viewing content¶
To retrieve a Content item and its information, you need to make use of the
The service should be injected into the constructor of your command or controller.
Content REST API
To learn how to load Content items using the REST API, see REST API reference.
To learn more about commands in Symfony, refer to Console Commands.
Viewing content metadata¶
Basic content metadata is available through
ContentInfo objects and their properties.
This value object provides primitive fields, such as
as well as methods for retrieving selected properties.
You can also use it to request other Content-related value objects from various services:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
ContentInfo is loaded from the
ContentService (line 9).
It provides you with basic content metadata such as modification and publication dates or main language code.
Retrieving content information in a controller
To retrieve content information in a controller, you also make use of the
but rendering specific elements (e.g. content information or Field values)
is relegated to templates.
To get the Locations of a Content item you need to make use of the
1 2 3 4
ContentInfo to get all the Locations of a Content item.
This method returns an array of
Location value objects.
For each Location, the code above prints out its
pathString (the internal representation of the path).
1 2 3 4 5 6
You can retrieve the Content Type of a Content item
getContentType method of the ContentInfo object:
To iterate over the versions of a Content item,
ContentService::loadVersions method, which returns an array of
VersionInfo value objects.
1 2 3 4 5 6
You can additionally provide the
loadVersions method with the version status
to get only versions of a specific status, e.g.:
Requesting version data may be impossible for an anonymous user. Make sure to authenticate as a user with sufficient permissions.
Content Relations are versioned.
To list Relations to and from your content,
you need to pass a
VersionInfo object to the
You can get the current version's
1 2 3 4 5 6
You can also specify the version number as the second argument to get Relations for a specific version:
loadRelations provides an array of
Relation has two main properties:
It also holds the relation type,
and the optional Field this relation is made with.
You can use the
getOwner method of the
ContentInfo object to load the Content item's owner as a
User value object.
To get the creator of the current version and not the Content item's owner,
you need to use the
creatorId property from the current version's
You can find the Section to which a Content item belongs through
of the ContentInfo object:
Note that requesting Section data may be impossible for an anonymous user. Make sure to authenticate as a user with sufficient permissions.
You can retrieve Object states of a Content item
You need to provide it with the Object state group.
All Object state groups can be retrieved through
1 2 3 4 5
Viewing content with Fields¶
To retrieve the Fields of the selected Content item, you can use the following command:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Lines 19-24 iterate over Fields defined by the Content Type.
For each Field they print out its identifier, and then using
FieldTypeService retrieve the Field's value and print it out to the console.
Viewing content in different languages¶
The Repository is SiteAccess-aware, so languages defined by the SiteAccess are automatically taken into account when loading content.
To load a specific language, provide its language code when loading the Content item:
To load all languages as a prioritized list, use
Getting all content in a subtree¶
To go through all the Content items contained in a subtree,
you need to use the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
loadLocation (line 14) returns a value object, here a
Refer to Searching for information on more complex search queries.
Getting parent Location¶
To get the parent Location of content, you first need to determine which Location is the main one,
in case the Content item has multiple Locations.
You can do it through the
getMainLocation method of the ContentInfo object.
Next, use the
getParentLocation method of the Location object to access the parent Location:
Getting content from a Location¶
When dealing with Location objects (and Trash objects), you can get access to Content item directly using
In Twig this can also be accessed by
This is a lazy property. It will trigger loading of content when first used. In case of bulk of Locations coming from Search or Location Service, the Content will also be loaded in bulk for the whole Location result set.
Comparing content versions¶
You can compare two versions of a Content item using the
The versions must have the same language.
For example, to get the comparison between the
name Field of two versions:
1 2 3 4
getComparisonResult returns a
ComparisonResult object, which depends on the Field Type being compared.
In the example of a Text Line (ezstring) Field, it is an array of
Each diff contains a section of the Field to compare (e.g. a part of a text line) and its status, which can be "unchanged", "added" or "removed".