0

enter image description here

I want to customize the article type node pages. I created a twig file :

node--article--full.html.twig

What code should I put in this file to display the "Description" field ?

/admin/structure/types/manage/article/fields

enter image description here

3 Answers 3

1

Rendered output of this field

{{ content.field_article_description }}
3
  • Thank you, it works. One last question. How to display a block and a flag on the page with twig ?
    – user83671
    Commented Mar 5, 2018 at 15:02
  • for block look at this drupal.stackexchange.com/questions/207377/… ... for flag not sure what you mean ... perhaps form a new question ?
    – GiorgosK
    Commented Mar 5, 2018 at 15:17
  • the fieldblock module can probably do what you are looking for, although there is also a chaos tools submodule that can give one view mode as a block. drupal.org/project/fieldblock
    – HongPong
    Commented Aug 3, 2018 at 20:50
1

Also note that if you need to exclude a specific field from the general content area even if it is set to display (which is what you have to do to get it into the render array) then this works:

   {#We hide the comments and links now so that we can render them later.#}
  <div{{ content_attributes }}>
    {{ content|without('comment', 'links', 'field_tags', 'field_machinename') }}
  </div>

and then where you need it to appear:

      {{ content.field_machinename }}
0

GiorgosK's answer should work, unless you have a layout set in the Manage Display tab, in which case you may need to use something like {{ content._field_layout.content.field_article_description }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.