Is there a way to use the views attachment as its own block? I would like to take the attachment from the "Glossary" view and output it elsewhere on my site.
2 Answers
You could try creating a block in a custom module using hook_block_info and hook_block_view. Then use views_embed_view to load the view and display it in your block.
This may look a little like this:
function my_module_block_info() {
$blocks['glossary_attachment'] = array(
'info' => t('Glossary Attachment'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
function my_module_block_view($delta = '') {
$block = array();
if ($delta == 'glossary_attachment') {
$block['subject'] = t('Glossary Attachment');
// Load the view.
$view = views_embed_view('glossary', 'attachment');
if ($view) {
$block['content'] = $view;
}
else {
$block['content'] = t('The view is empty');
}
}
return $block;
}
Perhaps it's possible to add a "Block" display to the same view ( Via add new Display tab ) and then to add the block to a page from Admin > Structure > Blocks
-
Unfortunately, I think doing that will mean I loose the contextual filters. So the ability to filter goes away.– RedRavenCommented Dec 31, 2012 at 6:27