In my Drupal 8 website I created a custom view mode through the UI. I use it to output nodes using a view.

In the view result I do not want the titles of the nodes to appear. The UI (content type > manage display) does not seem to give the option to hide the title.

How can I hide the title in a specific view mode for an entity via the UI or via custom code?

  • 2
    Given that the title field is a "normal" field now in D8 (compared to it being a "special" field back in de D7-days) I would expect to be able to hide it in the entity's manage display page. – batigolix Oct 23 '15 at 7:18
  • 1
    Apparently one has to install the title module to achieve this - drupal.org/node/2353867 – batigolix Sep 16 '16 at 20:41

The output of the title is different from the other fields. The reasons for that is, that the title is used for the title block and as metadata in the html head:

<!DOCTYPE html>
<html{{ html_attributes }}>
    <head-placeholder token="{{ placeholder_token|raw }}">
    <title>{{ head_title|safe_join(' | ') }}</title>

If the node is used in another context, for example when it is part of a view, the title is placed in the node template as {{ label }}:

  {% if not page %}
    <h2{{ title_attributes }}>
      <a href="{{ url }}" rel="bookmark">{{ label }}</a>
  {% endif %}

This is controlled by the variable page, a boolean, which is true, if the view mode is full. This is standard in drupal, when the node is displayed as main content and the title should appear in the head.

If you want to change this default behavior, you have to edit the node twig or change the variable page in preprocess.

In preprocess this would look like this:

function theme_preprocess(&$variables, $hook) {

   if ($hook == 'node') {
      if ( $variables['elements']['#view_mode'] == 'teaser' ) {
         $variables['page'] = true;

This will remove the title from the view mode teaser.


To answer the specific question in the latest comment, how to make the title field manageable in the display UI:

You have to change the field definition in a hook:

function mymodule_entity_base_field_info_alter(&$fields, $entity_type) {
  if ($entity_type->id() == 'node') {
    if (isset($fields['title'])) {
      $fields['title']->setDisplayConfigurable('view', TRUE);

Don't forget to remove {{ label }} from node twig, so that the title is not displayed twice.

  • 1
    Yes, I want to know this bit: "change the variables page/label/title in preprocess." I dont want to change to fields in the view because I want a standard approach to content layout in the whole site – batigolix Oct 23 '15 at 7:16
  • 1
    The standard approach would be to change the twig template, for example if you want to change the title display in the view of the taxonomy term (which is included in the standard install), you put a twig with the name "node--view--taxonomy-term.html.twig" in your template and remove there the title (named here as label), but if you prefer this in code, use the hook as mentioned in the answer and change 'teaser' to your custom view mode. – 4k4 Oct 23 '15 at 11:14
  • 2
    I would like to know how to achieve this using the manage display UI – batigolix Sep 16 '16 at 20:42
  • 1
    As mentioned in the answer, in a custom view mode this is not an option in ui. You need to make the base field title configurable first (with a custom module). The probem is still, that the title is hard coded in the twig. You would have to deal with this like mentioned in the answer. A better solution might be, to switch the view from displaying content to fields. – 4k4 Sep 16 '16 at 20:52
  • I've added a code example how to change the field definition (and edited the answer to the original question, there was some work to do to make it comprehensible) – 4k4 Sep 17 '16 at 12:59

Can do via UI with Display Suite:

Manage Display for the entity - at the bottom the Layout, set as One Column

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.