Reputation: 113
I'm trying to create my own custom format output of Views. I've had partial success with this code:
my_module.module:
<?php
function my_module_views_api() { // your module name into hook_views_api
return array(
'api' => 2,
// might not need the line below, but in any case, the last arg is the name of your module
'path' => drupal_get_path('module', 'my_module'),
);
}
?>
my_module.views.inc:
<?php
/**
* Implementation of hook_views_plugins().
*/
function my_module_views_plugins() {
$path = drupal_get_path('module', 'my_module');
return array(
'style' => array(
'my_module' => array(
'title' => t('my_module'),
'handler' => 'views_plugin_style_default',
'theme' => 'my_module',
'theme path' => $path . '/theme',
'theme file' => 'my-module.tpl.php',
'uses row plugin' => TRUE,
'uses row class' => TRUE,
'uses grouping' => TRUE,
'uses options' => TRUE,
'type' => 'normal',
)
),
);
}
?>
theme/my-module.tpl.php:
<?php
/**
* @file views-view-unformatted.tpl.php
* Default simple view template to display a list of rows.
*
* @ingroup views_templates
*/
if (!empty($title)):
print $title;
endif;
foreach ($rows as $id => $row):
?>
ROW:
<?php
print_r($row);
endforeach;
?>
The above is successful in that it will use my custom my-module.tpl.php to output rows. However, the rows are pre-formatted, presumable by the views_plugin_style_default handler. I've spent hours trying to create my own such handler, with no success, either placing it directly in the views/plugins directory or in my module's own plugins directory. I also can't find any good examples online and I don't get any useful error messages to help me debug.
Is there any proper documentation on how to create a custom views handler? Or can you provide a working example?
Thank you very much!
Upvotes: 1
Views: 3169
Reputation: 1577
There is a tutorial here: http://groups.drupal.org/node/10129. Scroll down to "Writing Views 2 style and row plugins". In the tutorial example, they create both a style and a row plugin.
As an alternative, I tried creating just a style plugin, similar to yours except I set 'uses row plugin' to false. I was then able to access the raw rowdata from within my views-view-myplugin.tpl.php template.
Upvotes: 1