I have a Content type containing a term reference field and some other fields. I have created 3 Display suite view modes for this content type. I want each node of this content type to be displayed in one of the defined DS view modes depending on the value of the term reference field of that node.

1 Answer 1


You can switch view modes using hook_entity_view_mode_alter. In pseudo code, something like:

function your_module_entity_view_mode_alter(&$view_mode, $context) {

    //check that this is a node of typex, and check current view mode
    if ($context['entity_type'] == 'node' && $context['entity']->type == 'typex' && $view_mode == 'full') {

      //check current taxonomy terms

      //code to set view mode
      if (condition based on taxonomy terms) {
        $view_mode = 'new_view_mode';

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.