Render content¶
Content is rendered automatically by using default, basic templates. To render content with a custom template, you create a template file and inform the system, through configuration, when to use this template.
You do it by using the content view configuration.
For example, to apply a custom template to all articles, add the following configuration:
1 2 3 4 5 6 7 8 9 |
|
This configuration defines a full
view for all content items that fulfill the conditions in match
.
match
indicates that all content items with the content type article
should use this configuration.
The indicated template
is @ibexadesign/full/article.html.twig
.
Designs
This configuration uses the design engine, as indicated by the @ibexadesign
in the template path.
In this example, the theme used by the design is my_theme
.
Using the design engine is recommended, but you can also set direct paths to templates, for example:
1 |
|
You must then ensure that the templates/full
folder contains the template file.
The configuration requires that you add the article.html.twig
template file to templates/themes/<theme_name>/full
,
in this example, templates/themes/my_theme/full
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Get content information¶
To render general content information, such as content name,
use the ibexa_content_name()
Twig function.
Content name is based on the content name pattern of the content type.
1 |
|
You can get general information about the content, Location and view parameters by using the available variables. For example, to get the publication date of the current content item, use:
1 |
|
Tip
For development purposes, you can list all available variables, or a single variable, and their values, by using the dump()
Twig function:
1 2 |
|
Render Fields¶
You can render a single Field of a content item by using the ibexa_render_field()
Twig function.
It takes the content item and the identifier of the Field as arguments:
1 |
|
You can pass additional arguments to this function, for example, an HTML class:
1 2 3 4 5 |
|
Field templates¶
You can use a custom Field template by passing the template as an argument to ibexa_render_field()
:
1 2 3 |
|
In this case you must place the author.html.twig
template in templates/themes/<theme_name>/fields
,
for example templates/themes/my_theme/fields
.
1 2 3 4 5 6 7 |
|
The Field template must be placed in a block that corresponds to the Field Type identifier,
in this case {% block ezauthor_field %}
.
Template blocks
Twig blocks are used to include templates in one another. For more information about relationships between templates, see Connecting templates.