I figure this is a pretty specific case and doesn't deserve to be included in the documentation for the module but, I'm curious to know how to go about doing this.
I'm using magic tabs to display 3 different views of nodes that are referencing the current node that the magic tabs are being displayed in. For example
Parent node: Show
(Magic tab) View of Referenced nodes: Reviews
(Magic tab) View of Referenced nodes: Videos
(Magic tab) View of Referenced nodes: Photo gallery
Everything works perfectly.
However, what I would like to do is conditionally show a tab if the view turns up any results. Here is what I have for my magic tabs code:
function magic_tabs_event_callback($active = 0) {
$photos = views_get_view('photos_ref');
$reviews = views_get_view('reviews_ref');
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
node_build_content($node);
}
$tabs[] = array(
'title' => t('Synopsis'),
'content' => $node->content['body']['#value'],
);
if ($photos) {
$tabs[] = array(
'title' => t('Photos'),
'content' => views_build_view('block', $photos, $view_args, FALSE, 28),
);
}
if (!empty($reviews)) {
$tabs[] = array(
'title' => t('Reviews'),
'content' => views_build_view('block', $reviews, $view_args, FALSE, 8),
);
}
return $tabs;
}
It seems that the if (!empty($reviews)) { is not doing anything. The conditional statement works fine on node->content fields just not for views.
Is this possible?
TIA,
txcrew
Comments
Comment #1
yhager commentedThis is more of a views question than magic_tabs, but I believe I have the answer for you.
in your code, $reviews is the view object itself, not the array of nodes. If you want to receive the array of nodes that is the result of the view, try something like:
For more information, see the documentation of views_build_view, in views.module.
Comment #2
Anonymous (not verified) commentedAhh. I should have known that.
Sorry for the post here. Will reference the views API next time.
I appreciate your time for the reply.
txcrew