diff --git a/docs/cheat-sheet.md b/docs/cheat-sheet.md
index 6e41179..42c4ff3 100644
--- a/docs/cheat-sheet.md
+++ b/docs/cheat-sheet.md
@@ -1,31 +1,35 @@
# Cheat sheet
## Drupal View
-Render a view. See Twig Tweak and Views page for more information.
+Render a view. See [Twig Tweak and Views](./views.md) page for more information.
### Accepted parameters
@@ -194,6 +221,8 @@ See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for details.
```
## Token Replace
+Replaces all tokens in a given string with appropriate values and returns the
+HTML.
```twig
{# Basic usage. #}
{{ '
[site:name]
[site:slogan]
'|token_replace }}
@@ -206,6 +235,8 @@ See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for details.
```
## Preg Replace
+Performs a regular expression search and replace. For simple string
+interpolation consider using built-in replace or format Twig filters.
```twig
{{ 'Drupal - community plumbing!'|preg_replace('/(Drupal)/', '
$1') }}
```
@@ -213,6 +244,10 @@ For simple string interpolation consider using built-in `replace` or `format`
Twig filters.
## Image Style
+Returns the URL of this image derivative for an original image path or URI. The
+returned value is the absolute URL where a style image can be downloaded, so
+it's suitable for use in an `
![]()
` tag. Requesting the URL will cause the image
+to be created.
```twig
{# Basic usage #}
{{ 'public://images/ocean.jpg'|image_style('thumbnail') }}
@@ -227,11 +262,15 @@ Twig filters.
images when used in an `
![]()
` tag.
## Transliterate
+Transliterates text from Unicode to US-ASCII. Returns a string with non-US-ASCII
+characters transliterated to US-ASCII characters, and unknown characters
+replaced with `$unknown_character`.
```twig
{{ 'Привет!'|transliterate }}
```
## Check Markup
+Runs all the enabled filters on a piece of text.
```twig
{{ '
bold strong'|check_markup('restricted_html') }}
```
@@ -243,6 +282,7 @@ Generates a string representation for the given byte count.
```
## Truncate
+Truncates a UTF-8-encoded string safely to a number of characters.
```twig
{# Truncates a UTF-8-encoded string safely to 10 characters. #}
{{ 'Some long text'|truncate(10) }}
@@ -252,8 +292,9 @@ Generates a string representation for the given byte count.
```
## View
+Returns a render array for entity, field list or field item.
```twig
-{# Do not put this into node.html.twig template to avoid recursion. #}
+{# Do not put these node entity examples into node.html.twig template to avoid recursion. #}
{{ node|view }}
{{ node|view('teaser') }}
@@ -264,7 +305,8 @@ Generates a string representation for the given byte count.
```
## With
-This is an opposite of core `without` filter.
+This filter is an opposite of core `without` filter: Adds new element to the
+array and returns the modified array.
```twig
{# Set top-level value. #}
{{ content.field_image|with('#title', 'Photo'|t) }}
@@ -274,6 +316,7 @@ This is an opposite of core `without` filter.
```
## Children
+Filters out the children of a render array, optionally sorted by weight.
```twig
{% for tag in content.field_tags|children %}
@@ -283,9 +326,9 @@ This is an opposite of core `without` filter.
```
## File URI
-When field item list is passed, the URI will be extracted from the first item.
-In order to get URI of specific item specify its delta explicitly using array
-notation.
+When a field item list is passed, the URI will be extracted from the first item.
+In order to get the URI of a specific item, specify its delta explicitly using
+array notation.
```twig
{{ node.field_image|file_uri }}
{{ node.field_image[0]|file_uri }}
@@ -297,8 +340,17 @@ it will return the URL to the resource, similar to the `file_url` filter.
{{ node.field_media|file_uri }}
```
+Useful to apply the `image_style` filter to Media fields. (Remember to check
+whether a URI is actually returned.)
+```twig
+{% set media_uri = node.field_media|file_uri %}
+{% if media_uri is not null %}
+ {{ media_uri|image_style('thumbnail') }}
+{% endif %}
+```
+
## File URL
-For string arguments it works similar to core `file_url()` Twig function.
+For string arguments it works similar to core [`file_url()`](https://www.drupal.org/docs/theming-drupal/twig-in-drupal/functions-in-twig-templates#s-file-urluri) Twig function.
```twig
{{ 'public://sea.jpg'|file_url }}
```
@@ -308,9 +360,9 @@ In order to generate absolute URL set "relative" parameter to `false`.
{{ 'public://sea.jpg'|file_url(false) }}
```
-When field item list is passed, the URL will be extracted from the first item.
-In order to get URL of specific item specify its delta explicitly using array
-notation.
+When a field item list is passed, the URL will be extracted from the first item.
+In order to get the URL of a specific item, specify its delta explicitly using
+array notation.
```twig
{{ node.field_image|file_url }}
{{ node.field_image[0]|file_url }}