Search code examples
drupaldrupal-8

How to display custom field content type to template page in page--front.html.twig?


I am new to Drupal & Curruntly learning on Drupal 8. I want to create HTML to Drupal dynamic conversion.

So for that I have created page--front.html.twig & Dynamic created page from backend as "Home Page" as front page. Hence It will automatically select the page--front.html.twig template. (Here I already added content type as Home page with custom fields)

Here for HTML to drupal first conversion All HTML codes I putted in page--front.html.twig & its related css & Js. So it will display static content.

Now I want to get all section content dynamically. So I have created other fields to that content type added some content into it but now I could not get that custom field value in template Front page using {{ content.field_test_field }}

I have used below codes,

{{ dump(content|keys) }}
{{ content.field_third_section_content.0 }}
{{ fields.field_third_section_content.content }}
{{ node.body.value|raw }}
{{ content.field_third_section_content }}
{{ node.field_third_section_content.0.value }}
{{ node.teaser.value }}

{{ dump(content|keys) }} for this I got array(0) { }

, Please give me some brief explanation So can know more about it syntax and functionality. & all above code is not working for me.

Please help me out to solve this issue.

Thank you in advance.


Solution

  • You can display fields for page--front.html.twig using the output types below :

    Remember to replace FIELDNAME with the name of your field.

    Outputting Blocks: {{ page.REGIONNAME }}

    Outputting Page Title: {{ node.title.value }}

    Outputting a Taxonomy Term or Dropdown Select option: {{ node.field_FIELDNAME.0.entity.label }}

    Outputting General Text Fields: {{ node.field_FIELDNAME.value }}

    Outputting Images or Files: {{ file_url(node.field_FIELDNAME.entity.fileuri')) }}