Skip to main content
update cheat sheet link
Source Link
2pha
  • 2.3k
  • 1
  • 14
  • 19

There are three handy methods for working with this, all of which save you time digging in complicated render arrays.

  1. Using Display Suite (with submodule ds_extras) you can assign to the hero region a block ("block region") which is a different display mode (i.e. just one containing the hero image). Thus you get two different display modes showing at once. Note that some preprocess hooks may not fire as you might expect if you do this.

  2. The twig_tweak module greatly simplifies such tasks and can give easier twig statements for field values. Take a look at the cheat sheetcheat sheet for some common uses: {{ drupal_field('field_image', 'node', 1) }} The function signature is: drupalField($field_name, $entity_type, $id = NULL, $view_mode = 'default', $langcode = NULL)

  3. The twig_field_value module makes simpler twig statements. Per README.txt: <img src={{ file_url(content.field_image|field_target_entity.uri.value) }} alt={{ content.field_image|field_raw('alt') }} />

If I had known this earlier, it would have saved me a great deal of time!

There are three handy methods for working with this, all of which save you time digging in complicated render arrays.

  1. Using Display Suite (with submodule ds_extras) you can assign to the hero region a block ("block region") which is a different display mode (i.e. just one containing the hero image). Thus you get two different display modes showing at once. Note that some preprocess hooks may not fire as you might expect if you do this.

  2. The twig_tweak module greatly simplifies such tasks and can give easier twig statements for field values. Take a look at the cheat sheet for some common uses: {{ drupal_field('field_image', 'node', 1) }} The function signature is: drupalField($field_name, $entity_type, $id = NULL, $view_mode = 'default', $langcode = NULL)

  3. The twig_field_value module makes simpler twig statements. Per README.txt: <img src={{ file_url(content.field_image|field_target_entity.uri.value) }} alt={{ content.field_image|field_raw('alt') }} />

If I had known this earlier, it would have saved me a great deal of time!

There are three handy methods for working with this, all of which save you time digging in complicated render arrays.

  1. Using Display Suite (with submodule ds_extras) you can assign to the hero region a block ("block region") which is a different display mode (i.e. just one containing the hero image). Thus you get two different display modes showing at once. Note that some preprocess hooks may not fire as you might expect if you do this.

  2. The twig_tweak module greatly simplifies such tasks and can give easier twig statements for field values. Take a look at the cheat sheet for some common uses: {{ drupal_field('field_image', 'node', 1) }} The function signature is: drupalField($field_name, $entity_type, $id = NULL, $view_mode = 'default', $langcode = NULL)

  3. The twig_field_value module makes simpler twig statements. Per README.txt: <img src={{ file_url(content.field_image|field_target_entity.uri.value) }} alt={{ content.field_image|field_raw('alt') }} />

If I had known this earlier, it would have saved me a great deal of time!

Source Link
HongPong
  • 270
  • 2
  • 10

There are three handy methods for working with this, all of which save you time digging in complicated render arrays.

  1. Using Display Suite (with submodule ds_extras) you can assign to the hero region a block ("block region") which is a different display mode (i.e. just one containing the hero image). Thus you get two different display modes showing at once. Note that some preprocess hooks may not fire as you might expect if you do this.

  2. The twig_tweak module greatly simplifies such tasks and can give easier twig statements for field values. Take a look at the cheat sheet for some common uses: {{ drupal_field('field_image', 'node', 1) }} The function signature is: drupalField($field_name, $entity_type, $id = NULL, $view_mode = 'default', $langcode = NULL)

  3. The twig_field_value module makes simpler twig statements. Per README.txt: <img src={{ file_url(content.field_image|field_target_entity.uri.value) }} alt={{ content.field_image|field_raw('alt') }} />

If I had known this earlier, it would have saved me a great deal of time!