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
-
$name
+
$name
String - Required - The name of the view to embed.
-
$display_id
-
String - Optional - The display id to embed. Default is default.
-
$...
+
$display_id
+
String - Optional - The display id to embed. Default is default.
+
$...
Mixed - Optional - Any additional parameters will be passed as arguments.
```twig {{ drupal_view('who_s_new', 'block_1') }} ``` -Specify additional parameters which map to contextual filters you have configured in your view: +Specify additional parameters which map to contextual filters you have +configured in your view: ```twig {{ drupal_view('who_s_new', 'block_1', arg_1, arg_2, arg_3) }} ``` ## Drupal View Result +Get the result of a view. ```twig {{ drupal_view_result('who_s_new', 'block_1') }} ``` ## Drupal Block +Used to render a block. + In order to figure out the plugin IDs list them using block plugin manager. With Drush, it can be done like follows: ```shell @@ -42,9 +46,12 @@ drush ev "print_r(array_keys(\Drupal::service('plugin.manager.block')->getDefini {{ drupal_block('system_branding_block', wrapper=false) }} ``` -See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for details. +See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for more details +and examples. ## Drupal Region +Used to render contents of a region from the default or any other specified +theme. ```twig {# Print 'sidebar_first' region of the default site theme. #} {{ drupal_region('sidebar_first') }} @@ -54,6 +61,7 @@ See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for details. ``` ## Drupal Entity +Used to render an entity. Returns `NULL` if the entity doesn't exist. ```twig {# Print a content block which ID is 1. #} {{ drupal_entity('block_content', 1) }} @@ -67,6 +75,7 @@ See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for details. ``` ## Drupal Entity Form +Gets the built and processed entity form for the given entity type. ```twig {# Print edit form for node 1. #} {{ drupal_entity_form('node', 1) }} @@ -79,6 +88,8 @@ See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for details. ``` ## Drupal Field +Returns the render array for a single entity field, or `NULL` if the field value +doesn't exist. ```twig {{ drupal_field('field_image', 'node', 1) }} {{ drupal_field('field_image', 'node', 1, 'teaser') }} @@ -86,6 +97,7 @@ See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for details. ``` ## Drupal Menu +Returns a render array for the specified menu. ```twig {# Print the top level of 'main' menu. #} {{ drupal_menu('main') }} @@ -95,11 +107,13 @@ See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for details. ``` ## Drupal Form +Returns a render array to represent the form. ```twig {{ drupal_form('Drupal\\search\\Form\\SearchBlockForm') }} ``` ## Drupal Image +Used to build the image. ```twig {# Render image specified by file ID. #} {{ drupal_image(123) }} @@ -118,16 +132,20 @@ See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for details. ``` ## Drupal Token +Replaces a given token with appropriate value. ```twig {{ drupal_token('site:name') }} ``` ## Drupal Config +Retrieves data from a given configuration object. ```twig {{ drupal_config('system.site', 'name') }} ``` ## Drupal Dump +Dumps information about variables. Alias `dd()` could be used instead of +`drupal_dump()`. You need to install Symfony VarDumper component. ```twig {# Basic usage. #} {{ drupal_dump(var) }} @@ -140,12 +158,15 @@ See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for details. ``` ## Drupal Title +Returns a title for the current route. ```twig {# The title is cached per URL. #} {{ drupal_title() }} ``` ## Drupal URL +Generates and returns a URL object from an internal path or `NULL` if URL is not +accessible to the user. ```twig {# Basic usage. #} {{ drupal_url('node/1') }} @@ -155,6 +176,8 @@ See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for details. ``` ## Drupal Link +Generates and returns a link object from an internal path or `NULL` if URL is +not accessible to the user. ```twig {# It supports the same options as drupal_url(), plus attributes. #} {{ drupal_link('View'|t, 'node/1', {attributes: {target: '_blank'}}) }} @@ -164,22 +187,26 @@ See [rendering blocks with Twig Tweak](blocks.md#block-plugin) for details. ``` ## Drupal Messages +Displays status messages. ```twig {{ drupal_messages() }} ``` ## Drupal Breadcrumb +Builds the breadcrumb. ```twig {{ drupal_breadcrumb() }} ``` ## Drupal Breakpoint +Emits a breakpoint to the debug client. ```twig {# Make Xdebug break on the specific line in the compiled Twig template. #} {{ drupal_breakpoint() }} ``` ## Contextual Links +Returns a renderable array representing contextual links. ```twig {# Basic usage. #}
@@ -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