CERN Accelerating science

Close menu

Content types

The content Type constitutes one of the core elements of a Drupal site. As already mentioned in the “How to Plan” section, most modern Web Frameworks support the concept of Entities. When it comes to Drupal websites the patterns are implemented using Content Types. A Content Type is a defined set of fields rendered in a specific way depending on the enabled theme.

How to create a Content Type

Every Drupal 8 website comes with 2 predefined Content Types: Article and Basic Page. Since those Content Type are almost never enough for most websites, the website admin has the ability to create his/her own custom Content Types. 

In order to create a custom Content Type:

  1. Visit <website_url>/admin/structure/types and click on “Add Content Type”
  2. Fill the field concerning general information of the content type:
    1. Name & Description - In general it is better to choose short and descriptive names for your Content Types 
    2. Publishing Options - It concerns Default options that a content will have when it is created. It is highly recommended to have your content not published by default in order to avoid mistakes when saving content. 
    3. Language Settings - Concerns the default language of your content and whether the content of this content type will be translatable.
  3. On the next screen, you can add and manage the fields of the created Content Type:
    1. Field Type (text, date, image etc) and Label of the field

       

      Adding field
    2. Based on the field type choice of the first screen, in the next screen you will have to fill some more information regarding the storage of the field that you created. For example, in our case, we created a text field and as a result we prompt to choose the maximum length of the words stored in this field

       

       

      field_settings
    3. The next screen is devoted to the form of that field. In other words, this screen defines the format of the input form when you create content out of this Content Type and you are prompt to fill the details of this field.
      1. Label - Sets the label that will be rendered on top of the input area of your field
      2. Help Text - Sets an optional help text under the input area of the field. It is highly recommended to fill this field, especially if you want to give specific instruction to the person who will create content of this content type (even if the person is you)
      3. Required Field - Defines whether this field will be required or not
         Required field
    4. Done! The field is added to your new content type.
  4. Done! The Content Type is created!

How to Manage how the input form of the content type will be displayed

When you create content out of a content type, you need to fill some defined input fields of the content type. In order to manage how those fields will be displayed, you just have to visit 

In order to manage how the input form will be displayed, you just have to visit <website_url>/admin/structure/types, then click on the arrow near “Manage fields” to expand your options and choose “Manage form display”.

From this page you can:

  • Reorder the field - by using drag-and-drop
  • Widget - used for the input and more options based on the field type.
  • More input options - by clicking the cog icon. Those options change based on the field type.

Input form

How to Manage how the rendered fields will be displayed
 

For every content type, you can manage how the fields of the content will be rendered. To manage the display options you need to visit <website_url>/admin/structure/types, then click on the arrow next to “Manage fields” in order to expand your options and choose “Manage Display”.

As an admin, you can apply the following customizations on the content of your content type. The customizations are done by field:

  • Reorder the fields - As you can see on the left of the field name there is an arrow cross that gives you the option to reorder the fields based on your needs.
  • Label rendering - Defines how the label of the field will be rendered:
    • Above - The label will be rendered above the field’s value
    • Inline - The label will be rendered on the same line as the field’s value
    • - Hidden - The label won’t be rendered
    • - Visually Hidden - The division of the label is rendered but not the value of the label
  • Format - Sets the format of the field, which depends on the field type. For example when the field is a text field you can choose to render it trimmed to a specific amount of characters. In a similar way, when the field is date field you can choose if the date will be rendered as the date itself or if you want to render how much time has passed since the date etc.

How to Create Content from a Content Type


Having created a Content Type, it can be used as a “mold” to create content out of it. To do this:

  1. Visit /node/add
  2. Choose the content type out of which you want to create the content
  3. Fill the fields which were defined in the content type. Pay attention in whether you want your content to be published or not. If you are unsure about the content, keep it unpublished. In addition, you can set the URL path if you want a custom URL to be set for the content that you will create.
  4. Done!

How to edit a created content

In order to edit a created content you just have to visit the content page /admin/content and click on the “Edit” button for the node that you want to edit.

  • More Option - For more options you can click the “cog” icon.
cog icon

 

Related FAQs