3

With Display Suite we can make custom view modes other then Teaser to use through out the site (in views for example). This is working fine and very nice!

However, using the custom view in a .tpl file does not work (where $teaser is confirmed to work).

Notice: Undefined variable: custom_view_mode_one in include() (line 92 of /home/dev/drupal-7.x/sites/.../node--custom-content-type.tpl.php). =>

do i need to register this in template.php even though it is already registered on the page and usable everywhere else?

2 Answers 2

1

$teaser is being passed in from template_preprocess_node(). DS just makes the view mode via a hook_entity_info; it doesn't wire it into the themeing system. You need to do something like this:

function MYTHEME_preprocess_node(&$variables) {
  $variables['custom_view_mode_one']
    = $variables['custom_view_mode_one'] == 'custom_view_mode_one';
}

You could also be smart by using a entity_get_info('node'), and get all of the view modes, and set similar variables.

Note that you should already have a variable called view_mode available in your template, too.

1
  • thanks, i put that in my template.php but it doesnt seem to work. Notice: Undefined index:
    – petergus
    Jan 16, 2013 at 11:44
0

Though slightly different i have accomplished my goal with the following in node.tpl

if ($node->type == 'custom_content_type_name' && $view_mode == 'custom_view_mode_') 

(node->type is optional)

What threw me off is that print render($content) must be in the else statement, otherwise things dont load and it looks like its not working.

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.