Skip to content

Commit

Permalink
IBX-7276: New User / Field twig functions (#2238)
Browse files Browse the repository at this point in the history
* New User / Field twig functions

* Implement review comments
---------

Co-authored-by: Adrien Dupuis <[email protected]>
  • Loading branch information
dabrt and adriendupuis authored Dec 22, 2023
1 parent cb59d52 commit d2a2bb8
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 17 deletions.
31 changes: 31 additions & 0 deletions docs/templating/twig_function_reference/field_twig_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ You can get additional information about a Field by using the following Twig fun
- [`ibexa_field_name()`](#ibexa_field_name) returns the name of a Content item's Field.
- [`ibexa_field_description()`](#ibexa_field_description) returns the description of a Content item's Field.
- [`ibexa_field_is_empty()`](#ibexa_field_is_empty) returns Boolean information whether a Field of a Content item is empty.
- [`ibexa_field_group_name()`](#ibexa_field_group_name) returns a human-readable name of the Field group.
- [`ibexa_has_field()`](#ibexa_has_field) checks whether a Field is present in the Content item.


## Field rendering

Expand Down Expand Up @@ -175,3 +178,31 @@ For example, use `ibexa_field_is_empty()` to check whether a Field is empty or f
{{ ibexa_render_field(content, 'image') }}
{% endif %}
```

### `ibexa_field_group_name()`

`ibexa_field_group_name()` returns a human-readable name of a Field group.

| Argument | Type | Description |
|---------------|------|-------------|
| `fieldGroupIdentifier` | `string` | Field group [identifier](repository_configuration.md#field-groups-configuration). |


``` html+twig
{{ ibexa_field_group_name('content') }}
```

### `ibexa_has_field()`

`ibexa_has_field()` returns Boolean information whether a Field is present in the Content item.

| Argument | Type | Description |
|---------------|------|-------------|
| `content` | `Ibexa\Contracts\Core\Repository\Values\Content\Content` | Content item the Field may belong to. |
| `fieldDefIdentifier` | `string` | Identifier of the Field. |

``` html+twig
{% if ibexa_has_field(content, 'existing') %}
{{ ibexa_render_field(content, 'existing') }}
{% endif %}
```
15 changes: 0 additions & 15 deletions docs/templating/twig_function_reference/other_twig_filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,6 @@ page_type: reference

# Other Twig filters

### `ibexa_user_get_current()`

`ibexa_user_get_current()` returns the User object (`Ibexa\Contracts\Core\Repository\Values\User\User`) of the current user.

``` html+twig
{{ ibexa_user_get_current().login }}
```

You can get the underlying Content item, for example the user's name,
by accessing the `content` property:

``` html+twig
{{ ibexa_render(ibexa_user_get_current().content) }}
```

### `ibexa_icon_path()`

`ibexa_icon_path()` generates a path to the selected icon from an icon set.
Expand Down
38 changes: 38 additions & 0 deletions docs/templating/twig_function_reference/user_twig_functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
description: User Twig functions enable getting repository user information.
page_type: reference
---

# User Twig functions

### `ibexa_user_get_current()`

`ibexa_user_get_current()` returns the User object (`Ibexa\Contracts\Core\Repository\Values\User\User`) of the current user.

``` html+twig
{{ ibexa_user_get_current().login }}
```

You can get the underlying Content item, for example to display the user's last name,
by accessing the `content` property:

``` html+twig
{{ ibexa_render_field(ibexa_user_get_current().content, 'last_name') }}
```

### `ibexa_current_user()`

`ibexa_current_user()` is a deprecated alias of `ibexa_user_get_current()`.


### `ibexa_is_current_user()`

The `ibexa_is_current_user()` Twig function checks whether a user is the current repository user.

#### Examples

```html+twig
{% if ibexa_is_current_user(version_info.author) %}
<!-- Display edit link -->
{% endif %}
```
5 changes: 3 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,13 @@ nav:
- Catalog Twig functions: templating/twig_function_reference/catalog_twig_functions.md
- Checkout Twig functions: templating/twig_function_reference/checkout_twig_functions.md
- Content Twig functions: templating/twig_function_reference/content_twig_functions.md
- Date Twig filters: templating/twig_function_reference/date_twig_filters.md
- Field Twig functions: templating/twig_function_reference/field_twig_functions.md
- Image Twig functions: templating/twig_function_reference/image_twig_functions.md
- Product Twig functions: templating/twig_function_reference/product_twig_functions.md
- Storefront Twig functions: templating/twig_function_reference/storefront_twig_functions.md
- Image Twig functions: templating/twig_function_reference/image_twig_functions.md
- URL Twig functions: templating/twig_function_reference/url_twig_functions.md
- Date Twig filters: templating/twig_function_reference/date_twig_filters.md
- User Twig functions: templating/twig_function_reference/user_twig_functions.md
- Other Twig filters: templating/twig_function_reference/other_twig_filters.md
- URLs and routes:
- URLs and routes: templating/urls_and_routes/urls_and_routes.md
Expand Down

0 comments on commit d2a2bb8

Please sign in to comment.