0

Background:

I have a Block view and content coming from content_block with number of fields.

So I want to access those fields value in custom template Is this possible? thanks

2

In a block twig you can access a field value like this:

{{ content['#block_content'].field_myfield.value }}

This is the database value of the field.

Most times you want to render a field:

{{ content.field_myfield }}

This will display the field as it is configured in the view mode.

0

Yes, it is possible with node template file. In node template file you get all the field values. please check this url for Twig Template naming conventions

1
  • content_block is rendered in bit special way than Nodes. Aug 23 '16 at 13:30
0

This works for me in block.html.twig on Drupal 8.3.4

{{ content.field_myfield[0] }}

The code above will directly display the value of field_myfield in the block.html.twig template

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.