Closed (works as designed)
Project:
Views (for Drupal 7)
Version:
6.x-2.0-rc1
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
24 Aug 2008 at 21:22 UTC
Updated:
24 Nov 2012 at 14:20 UTC
I've got a block view defined. I'm embedding it on the profile page thus:
print(views_embed_view('my_view', 'block_1'));It's working great, except I'm not getting the view's title. Is that the intended behavior? I could put that in manually, of course, but it seems like the view should write it out for me.
Comments
Comment #1
sprugman commentedoops. For some reason it didn't like my code, and I forgot to preview. Here's what I wrote in between the two paragraphs:
Comment #2
merlinofchaos commentedThat's right, embedding a view doesn't show the title. This is because the titles tend to be displayed separately from the content, which means you have to do that kind of thing yourself. Embed only prints the body of the view.
Comment #3
merlinofchaos commentedComment #4
sprugman commentedIs there, by chance, a handy function to print out the view's title, header, and/or footer? Those can change based on the view content, and it would be nice not to have to duplicate that logic in my module....
Comment #5
merlinofchaos commentedYou have to take apart views_embed_view() (it's short, really) and you can use
$view->get_title()and the slightly longer$view->display_handler->render_header()(as well as the complementary render_footer()).Note that the header & footer WILL appear in a view, so you shouldn't need to render them separately anyhow. They're part of the views-view template.
Which leads to another option: You could have the title embed itself in the views-view template, but if you do that then the title will double up in the block. So that's not necessarily a terrific solution.
Comment #6
sprugman commentedGot it, thanks.
Comment #7
VTM commentedCan you please help me with implementation of the command: $view->get_title()
The script that works for me is:
When using the following script, I get the text "Array":
Many thanks
Comment #8
merlinofchaos commentedUse $view->preview() instead of $view->execute_display() -- execute_display() returns what that display type thinks it needs. In this case, it's the array returned by hook_block($op = 'view');
Comment #9
VTM commentedpreview did the change. The block content is displayed correctly. Thanks.
It seems that the $view->get-title() is not working for me.
this is the code I use, and see no title:
Comment #10
pcambraIf you want the title of a specific display, you have to set the display first, as get_title doesn't have parameters.
Comment #11
anouIt should be :
If you put "print" on each line, you'll get a "1" before the title :-)
Comment #12
clecidor commentedIn Drupal 7:
Comment #13
zunaeid commentedTo render views block Drupal 7 I thing this is better
For views here
MODULE_NAME = "views";
DELTA = "VIEWS_NAME-DISPLAY_ID"