Views in Drupal are displayed as lists or simple tables. Is there a way to customize this?
I'd like my views to be rendered as JSON inside the page, so I can display it with some fancy JavaScript visualization.
Views in Drupal are displayed as lists or simple tables. Is there a way to customize this?
I'd like my views to be rendered as JSON inside the page, so I can display it with some fancy JavaScript visualization.
You can use views_datasource which will likely be the easiest way. If you need more flexibility, you can definitely handle this on your own, by using custom templates to markup the data in JSON.
To set the content-type, you could use a Views hook such as hook_views_pre_view() to add the header:
function mymodule_views_pre_view(&$view, &$display_id, &$args) {
if ($view->name == 'my_view') {
header('Content-type: text/javascript');
}
}
You will wonder, if you click on Theme: Information link in views editing, you will see all theming files of current display of view...