Skip to content

Latest commit

 

History

History
54 lines (35 loc) · 2.07 KB

File metadata and controls

54 lines (35 loc) · 2.07 KB
description Embed a content item in another using query types or controllers.

Embed related content

To embed content in another content item, you query for it in the repository. There are two ways to query for a content item:

Embed siblings with Query type

To render the Siblings of a content item (other content under the same parent Location), use the Siblings Query type.

To do it, use the built-in ibexa_query controller's contentQueryAction:

[[= include_file('code_samples/front/embed_content/config/packages/views.yaml', 8, 23) =]]

The results of the Siblings query are placed in the items variable, which you can use in the template:

[[= include_file('code_samples/front/embed_content/templates/themes/my_theme/full/blog_post.html.twig') =]]

Embed Relations with a custom controller

You can use a custom controller for any situation where Query types aren't sufficient.

[[= include_file('code_samples/front/embed_content/config/packages/views.yaml', 23, 30) =]]

This configuration points to a custom RelationController that should render all Articles with the showContentAction() method.

[[= include_file('code_samples/front/embed_content/src/Controller/RelationController.php') =]]

This controller uses the Public PHP API to get the Relations of a content item (lines 29-35).

The controller takes the custom parameter called accepted_content_types (line 25), which is an array of content type identifiers that are rendered.

This way you can control which content types you want to show or exclude.

Finally, the controller returns the view with the results that were provided in the items parameter. You can use this parameter as a variable in the template:

[[= include_file('code_samples/front/embed_content/templates/themes/my_theme/full/article.html.twig') =]]