Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.0-beta3
Component:
block displays
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
28 May 2008 at 03:54 UTC
Updated:
13 Aug 2008 at 21:32 UTC
I am using views_embed_view($view_name, 'block', $args) to embed a view into a node. My view has a number of different block displays associated with it. How can I specify which of the blocks I would like to embed?
Thanks.
Comments
Comment #1
merlinofchaos commentedEach block will have its own display id; this is probably easiest to find in the export, but it'll just be block1, block2, block3, etc, based upon the order you added them to the view.
Comment #2
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #3
mariagwyn commentedSorry to reopen this, but I am completely confused regarding how to embed a block from a custom view into a node. What I need is the exact syntax of
views_embed_view($view_name, 'block', $args)since I seem unable to figure it out myself. Here is the view info:View title: 'archive_reflections'
Block title: 'archive_reflections-block_1' (I think, hard to find this, but I hovered over the configure tab.
My failed PHP snippet:
I also tried 'block_1', '1', 'archive_reflections'...I am at a complete loss and am feeling pretty dumb. Any help?
Thanks,
Maria
Comment #4
merlinofchaos commentedThe id of that block is just 'block_1' which is what you'll use for the $display_id argument.
Comment #5
mariagwyn commentedSo I tried the following:
<?php $output = views_embed_view('archive_reflections', 'block_1'); ?>and
<?php $output = views_embed_view('archive_reflections', 'block_1', 'block_1'); ?>.Neither work. So, what am I missing? I am really confused. Obviously.
Comment #6
merlinofchaos commentedCan you please include an export of the view?
Comment #7
mariagwyn commentedMerlin, thanks for looking into this. Here is the export:
Comment #8
merlinofchaos commentedThe function you're calling appears to be correct based upon the view. But you're assigning the result to $output. Are you later doing a print $output? If not, maybe replace $output = with 'print'.3
Comment #9
mariagwyn commentedI have now tried all of the following, with no success:
First Try
2nd Try
3rd Try
4th Try
Can you actually type the whole function for me? I don't know php that well, and suspect I am missing something very obvious.
Thanks,
Maria
Comment #10
merlinofchaos commentedI think you just want:
print views_embed_view('archive_reflections', 'block_1');Comment #11
mariagwyn commentedjeez, that was sooooo easy! Thanks.
Comment #12
mariagwyn commentedokay, sorry to ask more questions, but, the code above does embed the block. But it embeds it with all the hidden fields that I have removed in the view display (such as a hidden "label" field). While no text appears in the area, the css creates the space for the text, which makes for very messy looking lists.
How can I embed the block exactly as it appears in a sidebar?
To see what I am talking about, visit: http://dev.mariagwyn.com/newskete/drupal/reflections.
The "Reflections" Block on the right is the view block on the sidebar. In the content area, there is a messy list under "Current Block." It is the reflections block inserted with the code above. What adjustment do I make to the code to call the block so it looks the same as it does in the right sidebar?
And where in the world is the documentation that explains the embed_view function? It is referred to...but I can't find it.
Thanks,
Maria
Comment #13
mariagwyn commentedany help?
m
Comment #14
merlinofchaos commentedSorry, I've been busy trying to get Panels 2 ported to D6 so I have less time for working Views issues. Not trying to ignore, but the issue queue volume is very high (at least, it is for just one person).
The issue you're having seems rather odd and I don't understand why the block would appear any different when embedded than when actually used. They should be identical. So I'm confused as to what's going on here.
Comment #15
mariagwyn commentedah, well, I love panels and am hoping to use it on 6 so no worries about the delay.
I am not sure how to better explain the issue, it does seem odd. Did you see the page I referred to? it shows the two versions. If you use firebug, you can see the hidden fields and compare with the reflections block to the right. Is there something slightly wrong in the code?
thanks,
m
Comment #16
merlinofchaos commentedI did see. I don't think there's anything wrong with your code; this may be a bug, but I just can't envision, in my head, where the bug might be.
Are you using the 'exclude' feature to not print certain fields?
Comment #17
mariagwyn commentedOdd. I switched the block to a table view rather than list view, and it is displaying correctly. It appears to be a problem with list view in particular and how it is generated. Here is the difference in code...notice the rather large number of break tags inserted in the incorrect version:
Content Version (incorrect):
Sidebar Version (correct):
Any ideas where this is happening, or where to bump this issue to make it more clear for someone who can actually correct this code within views?
Thanks,
Maria
Comment #18
merlinofchaos commentedHeh, sorry, I'm the Views guy -- there's nowhere to bump this issue to. =)
OH! Looking at this code...I think know what's happening!
It looks like the Views generated block is being passed through the linebreak filter. Do you have the linebreak filter on your PHP filter? If so, that's very likely the problem. Looking at this code, it looks like this is probably the only way those br tags could be getting in there is if they're generated afterward.
Things would appear to work as a table because the br tags would have very little effect amidst table tags.
Further evidence is that you'll also notice that a
<p>tag has been added. I'm sure that's the linebreak filter being applied to the Views output after it's already been given to you.Comment #19
mariagwyn commentedbingo! Thanks for being so consistently helpful (on this and other questions I have had).
Views is great by the way. I love that in 2.0 I can create multiple blocks/pages/etc all within one overarching views. Significantly cuts down on clutter.
Maria
Comment #20
mariagwyn commentedComment #21
mariagwyn commentedclearly, I believe in some sort of resurrection from the dead, or at least, am trying hard. So, sorry to resurrect, but I just realized...
When I embed the block view, the TITLE does not appear in the block. Is there a way to do this with arguments?
Thanks,
Maria
Comment #22
merlinofchaos commentedThe block system (and indeed, most of Drupal) has the title and the content printed separately, meaning that embedding the view you get only the content. To get the title you'll need to do a more complex job:
Comment #23
mariagwyn commentedthanks, very helpful! I am closing this again. ha!
maria
Comment #24
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.