Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/templating/twig_function_reference/date_twig_filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,33 @@ The filters also accept an optional `timezone` parameter for displaying date and
``` html+twig
{{ content.contentInfo.publishedDate|ibexa_short_datetime('PST') }}
```

## Considerations for usage outside back office
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds better IMO

Suggested change
## Considerations for usage outside back office
## Considerations for use outside the back office


The filters rely on user preferences.
When the preferences are not set, for example for logged out users, the filters fallback to a default date format.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When the preferences are not set, for example for logged out users, the filters fallback to a default date format.
When the preferences are not set, for example, for logged out users, the filters fallback to a default date format.

In case of some filters, the fallback date format contains locale-aware fragments, for example: full name of the month or day.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In case of some filters, the fallback date format contains locale-aware fragments, for example: full name of the month or day.
For some filters, the fallback date format includes locale-aware fragments, such as the full month or day name.

When combined with [reverse proxies like Varnish or Fastly](http_cache.md), it's possible to cache a localized version of a date and display it to other users, even if they're not using the same locale.

Consider these alternatives:

- Use Twig's built-in `date` filter with a fixed, locale-independent format

``` html+twig
{{ content.contentInfo.publishedDate|date('Y-m-d H:i:s') }}
```

- Use ESI for dynamic rendering of the date

``` html+twig
{{ render_esi(controller('App\\Controller\\CustomDateController::format', {
'date': content.contentInfo.publishedDate
})) }}
```

Don't cache the ESI response.
By implementing this solution, you can keep the date format locale-aware.

- Client-side JavaScript formatting

For more information, see [HTTP Cache](http_cache.md) and [Delivering personalized responses](context_aware_cache.md#personalize-responses).