Dear Yuval,

Thank you for your positive opinion for our website and for the the link. I agree that tabs implementation on our site is not best one, and probably will switch to the module that you've created.

But is it possible to display views with your module? The example in README file shows the content for the magic_tabs generated through:

'content' => t('Content of first magic tab')

How can we modify this line so that it could generate a view (for instance: $block = module_invoke('views', 'block', 'view', front_tasks_help); $tab=$block['content'];) on the fly?

Comments

yhager’s picture

Status: Active » Fixed

You just theme the view and put it in the 'content' key:

  $tabs[] = array(
    'title' => t('Your title'),
    'content' => theme('view', 'your-view-name'),
  );
yngens’s picture

hi,

can you tell how to call view's block instead of view itself?

thanks!

chadchandler’s picture

@ yngens,

Just duplicate the view, and uncheck "provide" page. Then it will call the block, or check out this module.

http://drupal.org/project/panels_tabs

chadchandler’s picture

Edited to add:

What would be the correct snippit to print a custom block?

Example:

<?php
function magic_tabs_test_callback() {
  $tabs[] = array(
    'title' => t('Top Rated'),
    'content' => t('Would like this to be a custom block with the name Rated'),
  );
  $tabs[] = array(
    'title' => t('Top Hated'),
    'content' => t('Would like this to be a custom block with the name Hated'),
  );
  return $tabs;
}
?>
yngens’s picture

Thanks Prodigy. I knew of that method. But probably there is a way to call view's block (preserving page view itself too) directly via theme function, isn't there?

yhager’s picture

@yngens: In that case you can use:

  $tabs[] = array(
    'title' => t('Your title'),
    'content' => theme('view', 'your-view-name', NULL, NULL, 'block'),
  );

@Prodigy: there's no easy way to do that. I'll add the required code to the module.

chadchandler’s picture

I was just trying a bunch of different ways I thought would work, but they wouldn't.
I try to avoid views whenever I can just do the SQL myself for a block, so if this could be patched in , or if it is already possible calling in custom blocks would be uber fantastic.

yhager’s picture

I'll add easier way to do this with all kinds of blocks, not just custom, but for the meantime you can use:

  $bid = 2;
  $block = (object)module_invoke('block', 'block', 'view', $bid);
  $block->module = 'block';
  $block->delta = $bid;
  $tabs[] = array(
    'title' => t('Display a custom block'),
    'content' => theme('block', $block),
  );

(assign your own block id to $bid)

chadchandler’s picture

Great! Thanks and I will test this first thing in the morning. This seems easy enough. I'll report back.

yngens’s picture

#7
Prodigy - May 27, 2008 - 19:46

I was just trying a bunch of different ways I thought would work, but they wouldn't.
I try to avoid views whenever I can just do the SQL myself for a block, so if this could be patched in , or if it is already possible calling in custom blocks would be uber fantastic.

Prodigy, may I ask why do you do that? Obviously, to gain some performance? But is the difference so much? Does it worth it?
I am asking this because if it really worth it, I also would like to switch making direct MySQL calls instead of using views.

yngens’s picture

thanks, yhager, for #6. works great!

another question - is it possible to suppress displaying pager in a block? in my views settings for the block there is no pager used, nevertheless magic-tabs displays my block with the pager.

yhager’s picture

@yngens: I'm happy to help, but these are all generic views issues, unrelated to magic tabs.
If you want to display a limited amount of items in your block and no pager, use values instead of the 'NULL, NULL' we wrote above.
Consult the documentation at http://api.freestylesystems.co.uk/api/function/theme_view/5 (or in your views.module local install - search for theme_view())

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

alex_shapka’s picture

Issue summary: View changes

Deleted the direct link to my website