Skip to content

Commit d22a080

Browse files
committed
Added mention about the date filters
1 parent bab5296 commit d22a080

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/templating/twig_function_reference/date_twig_filters.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,33 @@ The filters also accept an optional `timezone` parameter for displaying date and
2525
``` html+twig
2626
{{ content.contentInfo.publishedDate|ibexa_short_datetime('PST') }}
2727
```
28+
29+
## Considerations for usage outside back office
30+
31+
The filters rely on user preferences.
32+
When the preferences are not set, for example for logged out users, the filters fallback to a default date format.
33+
In case of some filters, the fallback date format contains locale-aware fragments (for example: full name of the month or day).
34+
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.
35+
36+
Consider these alternatives:
37+
38+
- Use Twig's built-in `date` filter with a fixed, locale-indenepdent format
39+
40+
``` html+twig
41+
{{ content.contentInfo.publishedDate|date('Y-m-d H:i:s') }}
42+
```
43+
44+
- Use ESI for dynamic rendering of the date
45+
46+
``` html+twig
47+
{{ render_esi(controller('App\\Controller\\CustomDateController::format', {
48+
'date': content.contentInfo.publishedDate
49+
})) }}
50+
```
51+
52+
Don't cache the ESI response.
53+
By implementing this solution, you can keep the date format locale-aware.
54+
55+
- Client-side JavaScript formatting
56+
57+
For more information, see [HTTP Cache](http_cache.md) and [Delivering personalized responses](context_aware_cache.md#personalize-responses).

0 commit comments

Comments
 (0)