Drupal 6: Embeding View in a block

Submitted by programmer on Tue, 01/13/2009 - 10:22.
::

function hook_block($op = 'list', $delta = 0, $edit = array()) {

    switch ($op) {
        case 'list':
            $blocks[0]['info'] = t('Example Block');
            return $blocks;


        case 'view':
        default:

            $view = views_get_view('view_name');
             $view->set_display('default');
            $view->set_arguments(array(arg(2)));


            $output = '';
            $output = $view->render();
           $block['content'] = $output;
            return $block;

            break;
    }
}

 

 

Post your Answer

  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options