2

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 2

3

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;
}
1
  • Can you answer this Question
    – Umair
    Commented Jun 12, 2017 at 19:20
0

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

1
  • Unfortunately, I think doing that will mean I loose the contextual filters. So the ability to filter goes away.
    – RedRaven
    Commented Dec 31, 2012 at 6:27

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.