0

I have a style plugin, 'mystyle'. And I created a view, 'myview', with style set to 'mystyle'.

Here is the declaration of 'mystyle' in hook_view_plugins:

function mymodule_views_plugins() {
  $plugins = array(
    'module' => 'mymodule',
    'style' => array(
      'mystyle' => array(
        'title' => t('My Style'),
        'handler' => 'mymodule_views_plugin_mystyle',
        'theme' => 'mymodule_views_plugin_mystyle_template',
        'uses fields' => TRUE,
        'uses row plugin' => FALSE,
        'uses options' => TRUE,
        'uses grouping' => FALSE,
        'type' => 'normal',
        'even empty' => FALSE,
      ),
    )
  );
  return $plugins;
}

I have the following files in mymodule/views:

(handler) mymodule_views_plugin_mystyle.inc

(template associated with this style) mymodule-views-plugin-mystyle-template.tpl.php

(template associated with this style, and customized for the view 'myview') mymodule-views-plugin-mystyle-template--myview.tpl.php

My problem: Views is using the first, less specific, template (mymodule-views-plugin-mystyle-template.tpl.php) to display this view.

When I edit 'myview' and click on "theme information", I see both templates listed under "style output":

  • mymodule-views-plugin-mystyle-template.tpl.php
  • mymodule-views-plugin-mystyle-template--myview.tpl.php

The first, less specific, template is in bold. If I understand correctly, this means that views found the first template but did not find the second.

I have tried rescanning, but that does not help. I have also tried deleting the cache.

Should this work? What do I need to do to get views to find the more specific template?

1

Drupal by default doesn't scan for more specific templates in modules directories, but views allows you to do it by adding 'template path' to hook_views_api(), see: https://api.drupal.org/api/views/views.api.php/function/hook_views_api/7.x-3.x

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.