Skip to content

Commit d2a2bb8

Browse files
dabrtadriendupuis
andauthored
IBX-7276: New User / Field twig functions (#2238)
* New User / Field twig functions * Implement review comments --------- Co-authored-by: Adrien Dupuis <[email protected]>
1 parent cb59d52 commit d2a2bb8

File tree

4 files changed

+72
-17
lines changed

4 files changed

+72
-17
lines changed

docs/templating/twig_function_reference/field_twig_functions.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ You can get additional information about a Field by using the following Twig fun
2020
- [`ibexa_field_name()`](#ibexa_field_name) returns the name of a Content item's Field.
2121
- [`ibexa_field_description()`](#ibexa_field_description) returns the description of a Content item's Field.
2222
- [`ibexa_field_is_empty()`](#ibexa_field_is_empty) returns Boolean information whether a Field of a Content item is empty.
23+
- [`ibexa_field_group_name()`](#ibexa_field_group_name) returns a human-readable name of the Field group.
24+
- [`ibexa_has_field()`](#ibexa_has_field) checks whether a Field is present in the Content item.
25+
2326

2427
## Field rendering
2528

@@ -175,3 +178,31 @@ For example, use `ibexa_field_is_empty()` to check whether a Field is empty or f
175178
{{ ibexa_render_field(content, 'image') }}
176179
{% endif %}
177180
```
181+
182+
### `ibexa_field_group_name()`
183+
184+
`ibexa_field_group_name()` returns a human-readable name of a Field group.
185+
186+
| Argument | Type | Description |
187+
|---------------|------|-------------|
188+
| `fieldGroupIdentifier` | `string` | Field group [identifier](repository_configuration.md#field-groups-configuration). |
189+
190+
191+
``` html+twig
192+
{{ ibexa_field_group_name('content') }}
193+
```
194+
195+
### `ibexa_has_field()`
196+
197+
`ibexa_has_field()` returns Boolean information whether a Field is present in the Content item.
198+
199+
| Argument | Type | Description |
200+
|---------------|------|-------------|
201+
| `content` | `Ibexa\Contracts\Core\Repository\Values\Content\Content` | Content item the Field may belong to. |
202+
| `fieldDefIdentifier` | `string` | Identifier of the Field. |
203+
204+
``` html+twig
205+
{% if ibexa_has_field(content, 'existing') %}
206+
{{ ibexa_render_field(content, 'existing') }}
207+
{% endif %}
208+
```

docs/templating/twig_function_reference/other_twig_filters.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,6 @@ page_type: reference
44

55
# Other Twig filters
66

7-
### `ibexa_user_get_current()`
8-
9-
`ibexa_user_get_current()` returns the User object (`Ibexa\Contracts\Core\Repository\Values\User\User`) of the current user.
10-
11-
``` html+twig
12-
{{ ibexa_user_get_current().login }}
13-
```
14-
15-
You can get the underlying Content item, for example the user's name,
16-
by accessing the `content` property:
17-
18-
``` html+twig
19-
{{ ibexa_render(ibexa_user_get_current().content) }}
20-
```
21-
227
### `ibexa_icon_path()`
238

249
`ibexa_icon_path()` generates a path to the selected icon from an icon set.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
description: User Twig functions enable getting repository user information.
3+
page_type: reference
4+
---
5+
6+
# User Twig functions
7+
8+
### `ibexa_user_get_current()`
9+
10+
`ibexa_user_get_current()` returns the User object (`Ibexa\Contracts\Core\Repository\Values\User\User`) of the current user.
11+
12+
``` html+twig
13+
{{ ibexa_user_get_current().login }}
14+
```
15+
16+
You can get the underlying Content item, for example to display the user's last name,
17+
by accessing the `content` property:
18+
19+
``` html+twig
20+
{{ ibexa_render_field(ibexa_user_get_current().content, 'last_name') }}
21+
```
22+
23+
### `ibexa_current_user()`
24+
25+
`ibexa_current_user()` is a deprecated alias of `ibexa_user_get_current()`.
26+
27+
28+
### `ibexa_is_current_user()`
29+
30+
The `ibexa_is_current_user()` Twig function checks whether a user is the current repository user.
31+
32+
#### Examples
33+
34+
```html+twig
35+
{% if ibexa_is_current_user(version_info.author) %}
36+
<!-- Display edit link -->
37+
{% endif %}
38+
```

mkdocs.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,13 @@ nav:
274274
- Catalog Twig functions: templating/twig_function_reference/catalog_twig_functions.md
275275
- Checkout Twig functions: templating/twig_function_reference/checkout_twig_functions.md
276276
- Content Twig functions: templating/twig_function_reference/content_twig_functions.md
277+
- Date Twig filters: templating/twig_function_reference/date_twig_filters.md
277278
- Field Twig functions: templating/twig_function_reference/field_twig_functions.md
279+
- Image Twig functions: templating/twig_function_reference/image_twig_functions.md
278280
- Product Twig functions: templating/twig_function_reference/product_twig_functions.md
279281
- Storefront Twig functions: templating/twig_function_reference/storefront_twig_functions.md
280-
- Image Twig functions: templating/twig_function_reference/image_twig_functions.md
281282
- URL Twig functions: templating/twig_function_reference/url_twig_functions.md
282-
- Date Twig filters: templating/twig_function_reference/date_twig_filters.md
283+
- User Twig functions: templating/twig_function_reference/user_twig_functions.md
283284
- Other Twig filters: templating/twig_function_reference/other_twig_filters.md
284285
- URLs and routes:
285286
- URLs and routes: templating/urls_and_routes/urls_and_routes.md

0 commit comments

Comments
 (0)