Browse Source

Format examples

merge-requests/4/head
Chi 6 years ago
parent
commit
d84e7e30af
  1. 60
      src/TwigExtension.php

60
src/TwigExtension.php

@ -104,13 +104,13 @@ class TwigExtension extends \Twig_Extension {
* *
* Examples: * Examples:
* @code * @code
* # Print block using default configuration. * {# Print block using default configuration. #}
* {{ drupal_block('system_branding_block') }} * {{ drupal_block('system_branding_block') }}
* *
* # Print block using custom configuration. * {# Print block using custom configuration. #}
* {{ drupal_block('system_branding_block', {label: 'Branding', use_site_name: false}) * {{ drupal_block('system_branding_block', {label: 'Branding', use_site_name: false})
* *
* # Bypass block.html.twig theming. * {# Bypass block.html.twig theming. #}
* {{ drupal_block('system_branding_block', wrapper=false) }} * {{ drupal_block('system_branding_block', wrapper=false) }}
* @endcode * @endcode
* *
@ -185,10 +185,10 @@ class TwigExtension extends \Twig_Extension {
* *
* Examples: * Examples:
* @code * @code
* # Print 'Sidebar First' region of the default site theme. * {# Print 'Sidebar First' region of the default site theme. #}
* {{ drupal_region('sidebar_first') }} * {{ drupal_region('sidebar_first') }}
* *
* # Print 'Sidebar First' region of Bartik theme. * {# Print 'Sidebar First' region of Bartik theme. #}
* {{ drupal_region('sidebar_first', 'bartik') }} * {{ drupal_region('sidebar_first', 'bartik') }}
* @endcode * @endcode
* *
@ -239,14 +239,14 @@ class TwigExtension extends \Twig_Extension {
* *
* Examples: * Examples:
* @code * @code
* # Print a content block which ID is 1. * {# Print a content block which ID is 1. #}
* {{ drupal_entity('block_content', 1) }} * {{ drupal_entity('block_content', 1) }}
* *
* # Print a node's teaser. * {# Print a node's teaser. #}
* {{ drupal_entity('node', 123, 'teaser') }} * {{ drupal_entity('node', 123, 'teaser') }}
* *
* # Print Branding block which was previously disabled on * {# Print Branding block which was previously disabled on #}
* # admin/structure/block page. * {# admin/structure/block page. #}
* {{ drupal_entity('block', 'bartik_branding', check_access=false) }} * {{ drupal_entity('block', 'bartik_branding', check_access=false) }}
* @endcode * @endcode
* *
@ -285,13 +285,13 @@ class TwigExtension extends \Twig_Extension {
* *
* Examples: * Examples:
* @code * @code
* # Print edit form for node 1. * {# Print edit form for node 1. #}
* {{ drupal_entity_form('node', 1) }} * {{ drupal_entity_form('node', 1) }}
* *
* # Print add form for Article content type. * {# Print add form for Article content type. #}
* {{ drupal_entity_form('node', values={type: 'article'}) }} * {{ drupal_entity_form('node', values={type: 'article'}) }}
* *
* # Print user register form. * {# Print user register form. #}
* {{ drupal_entity_form('user', NULL, 'register', check_access=false) }} * {{ drupal_entity_form('user', NULL, 'register', check_access=false) }}
* @endcode * @endcode
* *
@ -443,19 +443,19 @@ class TwigExtension extends \Twig_Extension {
* *
* Examples: * Examples:
* @code * @code
* # Render image specified by file ID. * {# Render image specified by file ID. #}
* {{ drupal_image(123) }} * {{ drupal_image(123) }}
* *
* # Render image specified by file UUID. * {# Render image specified by file UUID. #}
* {{ drupal_image('9bb27144-e6b2-4847-bd24-adcc59613ec0') }} * {{ drupal_image('9bb27144-e6b2-4847-bd24-adcc59613ec0') }}
* *
* # Render image specified by file URI. * {# Render image specified by file URI. #}
* {{ drupal_image('public://ocean.jpg') }} * {{ drupal_image('public://ocean.jpg') }}
* *
* # Render image using 'thumbnail' image style and custom attributes. * {# Render image using 'thumbnail' image style and custom attributes. #}
* {{ drupal_image('public://ocean.jpg', 'thumbnail', {alt: 'The alternative text'|t, title: 'The title text'|t}) }} * {{ drupal_image('public://ocean.jpg', 'thumbnail', {alt: 'The alternative text'|t, title: 'The title text'|t}) }}
* *
* # Render responsive image. * {# Render responsive image. #}
* {{ drupal_image('public://ocean.jpg', 'wide', responsive=true) }} * {{ drupal_image('public://ocean.jpg', 'wide', responsive=true) }}
* @endcode * @endcode
* *
@ -577,13 +577,13 @@ class TwigExtension extends \Twig_Extension {
* *
* Examples: * Examples:
* @code * @code
* # Basic usage. * {# Basic usage. #}
* {{ drupal_dump(var) }} * {{ drupal_dump(var) }}
* *
* # Same as above but shorter. * {# Same as above but shorter. #}
* {{ dd(var) }} * {{ dd(var) }}
* *
* # Dump all available variables for the current template. * {# Dump all available variables for the current template. #}
* {{ dd() }} * {{ dd() }}
* @endcode * @endcode
* *
@ -623,10 +623,10 @@ class TwigExtension extends \Twig_Extension {
* *
* Examples: * Examples:
* @code * @code
* # Basic usage. * {# Basic usage. #}
* {{ drupal_url('node/1) }} * {{ drupal_url('node/1) }}
* *
* # Complex URL. * {# Complex URL. #}
* {{ drupal_url('node/1', {query: {foo: 'bar'}, fragment: 'example', absolute: true}) }} * {{ drupal_url('node/1', {query: {foo: 'bar'}, fragment: 'example', absolute: true}) }}
* @endcode * @endcode
* *
@ -663,10 +663,10 @@ class TwigExtension extends \Twig_Extension {
* *
* Examples: * Examples:
* @code * @code
* # It supports the same options as drupal_url(), plus attributes. * {# It supports the same options as drupal_url(), plus attributes. #}
* {{ drupal_link('View'|t, 'node/1', {attributes: {target: '_blank'}}) }} * {{ drupal_link('View'|t, 'node/1', {attributes: {target: '_blank'}}) }}
* *
* # This link will only be shown for privileged users. * {# This link will only be shown for privileged users. #}
* {{ drupal_link('Example'|t, '/admin', check_access=true) }} * {{ drupal_link('Example'|t, '/admin', check_access=true) }}
* @endcode * @endcode
* *
@ -718,13 +718,13 @@ class TwigExtension extends \Twig_Extension {
* *
* Examples: * Examples:
* @code * @code
* # Basic usage. * {# Basic usage. #}
* <div class="contextual-region"> * <div class="contextual-region">
* {{ contextual_links('entity.view.edit_form:view=frontpage&display_id=feed_1') }} * {{ contextual_links('entity.view.edit_form:view=frontpage&display_id=feed_1') }}
* {{ drupal_view('frontpage') }} * {{ drupal_view('frontpage') }}
* </div> * </div>
* *
* # Multiple links. * {# Multiple links. #}
* <div class="contextual-region"> * <div class="contextual-region">
* {{ contextual_links('node:node=123|block_content:block_content=123') }} * {{ contextual_links('node:node=123|block_content:block_content=123') }}
* {{ content }} * {{ content }}
@ -770,10 +770,10 @@ class TwigExtension extends \Twig_Extension {
* *
* Example: * Example:
* @code * @code
* # Basic usage. * {# Basic usage. #}
* {{ '<h1>[site:name]</h1><div>[site:slogan]</div>'|token_replace }} * {{ '<h1>[site:name]</h1><div>[site:slogan]</div>'|token_replace }}
* *
* # This is more suited to large markup (requires Twig >= 1.41). * {# This is more suited to large markup (requires Twig >= 1.41). #}
* {% apply token_replace %} * {% apply token_replace %}
* <h1>[site:name]</h1> * <h1>[site:name]</h1>
* <div>[site:slogan]</div> * <div>[site:slogan]</div>
@ -938,10 +938,10 @@ class TwigExtension extends \Twig_Extension {
* *
* Examples: * Examples:
* @code * @code
* # Set top level value. * {# Set top level value. #}
* {{ content.field_image|with('#title', 'Photo'|t) }} * {{ content.field_image|with('#title', 'Photo'|t) }}
* *
* # Set nested value. * {# Set nested value. #}
* {{ content|with(['field_image', '#title'], 'Photo'|t) }} * {{ content|with(['field_image', '#title'], 'Photo'|t) }}
* @endcode * @endcode
* *

Loading…
Cancel
Save