1

I have an entityreference field that displays content in a custom view mode. It works great.

The only problem is that in addition to the fields that I placed in my custom view mode, it also displays the title as a link to the content. I would like to replace it and have another field (that is already in the view mode) be used as the link to the content. Also the title is appearing in the markup outside the entityreference field's view mode's wrapper, making styling a bit cumbersome.

So right now I have something like the following as field output

The title of the node

headline

My cool description that has some words in it

[and a picture]

I want essentially the same thing, but minus the title, and with the headline as the link, like so:

headline

My cool description that has some words in it

[and a picture]

How do I go about getting rid of the title and substituting the headline?

3 Answers 3

1

I had almost the same problem as you recently. Eventually I changed the node--content-type.tpl files of the referenced content type tot suit my needs.

2

You could do this with display suite as follows:

  1. Enable display suite and display suite extras (important)
  2. At structure > ds > list > extras > Other, enable Page title options
  3. At Manage Display > [view mode] > [layout], enable a DS layout for your view mode
  4. Manage Display > [view mode] > custom page title, hide the page title

DS has a lot going on. But if you need custom display modes and need to hide the page title in some cases it works well. Plus you get a lot of other nice features.

1
  • This is hard to follow, but worth finding. See: /admin/structure/ds/list/extras
    – doublejosh
    Commented Jun 28, 2017 at 21:30
1

If you don't want to use display suite, you can create a new view mode in your custom module like so:

function MYMODULE_entity_info_alter(&$entity_info) {
  $entity_info['node']['view modes']['VIEW_MODE_NAME'] = array(
    'label' => t('VIEW_MODE_NAME'),
    'custom settings' => TRUE,
  );
}

You can administer the new view mode in the display settings for each content type. You can also enable custom template files for the view modes of each content type by adding the following in your theme's template.php file:

function MYTHEME_preprocess_node(&$vars) {
 switch($vars['view_mode'] ){
    case 'MY_VIEW_MODE':
      $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__MY_VIEW_MODE';
      break;
    case 'teaser':
      $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__teaser';
      break;
  }
}

This enables you to create template files with filenames like node--CONTENT_TYPE--MY_VIEW_MODE.tpl.php.

Your Answer

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

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