Drupal 6: Embeding View in a block

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


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 Comment

  • 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 <% ... %>.