Closed (won't fix)
Project:
Views (for Drupal 7)
Version:
6.x-2.11
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
15 Apr 2008 at 03:15 UTC
Updated:
27 Aug 2013 at 20:52 UTC
Jump to comment: Most recent
Comments
Comment #1
merlinofchaos commentedTry this:
Comment #2
merlinofchaos commentedComment #3
bensnyder commentedmerlin I absolutely love you! thanks! and GREAT work on views!!! The UI has made leaps and bounds!
Comment #4
bensnyder commentedmerlin, check this out: (its my testing site)
pegleglax.homeip.net/sertoma
see the error views creates?
Comment #5
merlinofchaos commentedBe sure the $args you pass is an array. I think you can just leave the argument off if you don't have args at all.
Comment #6
bensnyder commentedworks!!!! Thanks!
Comment #7
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #8
vj0914 commentedwhat should i do if I want to embed 2 views on same page?
Comment #9
vj0914 commentedI figured out, Thanks
Comment #10
Matthew Davidson commentedAnd just to elaborate, you can change 'default' to whatever display id you want ('page_1', 'block_1', 'block_2'), eg.:
This is necessary if you want your embedded view to pick up any of your customised theming.
Comment #11
deviantintegral commentedHas anyone else had issues with node titles being changed when you call execute_display? I'm calling it at the end of my node.tpl.php, and it seems to somehow be overriding the node's title with it's own, even though the title field should have all ready been printed. It's like the call to execute_display is getting the entire theme engine reset and redone. I'll keep on it, but I was hoping somehow that this isn't an issue with views and is just my site :)
Thanks,
--Andrew
Comment #12
Matthew Davidson commentedYou should create a new issue for this. It's a different question to the one in the parent post, which has been resolved. Be nice to merlin.
Comment #13
merlinofchaos commentedNever ever ever use execute_display() to embed a view. Always use preview(). See views_embed_view() for the canonical example.
view::execute_display() should only be used where the display handler was intended to be used. i.e, a 'page' display should only use execute_display via a proper page callback, and a 'block' display should only use execute_display via hook_block.
Comment #14
deviantintegral commentedThank you - calling views_embed_view() is working perfectly!
For reference, my snippet:
--Andrew
Comment #15
merlinofchaos commentedI think you'll find that the first part of all that can be eliminated by using the arg() function.
arg(1) perhaps.
Comment #16
deviantintegral commentedYeah, I used to hope so too Merlin :). The problem is that I'm grabbing the argument from a URL alias set with the pathauto. When you call arg(), you get the internal system path of the node you're looking at, and last I looked there was no Drupal API to easily get the unchanged path to the current page. Though it's probably better to call drupal_get_path_alias() with $_GET['q'], and then you avoid the removal of ?q=.
--Andrew
Comment #17
merlinofchaos commentedactually no, you're right the first time. If you call drupal_get_path_alias() you'll do a database lookup and if it's a URL with multiple aliases you will always get the same one regardless of which alias was actually used.
Comment #18
Archie Bunker commentedI'd like to hook a filter into this view in my node-games.tpl.php file as I can't figure out how to do this with argument handling directly in the views 2 admin tool. Can I do something like this? Can't seem to get it to work. So close.....Yet so far.
If not, where can I place this function so that this works? FYI - Basically what this is saying is "Take a [game content type] node and find all the games for the home team [home team is a node reference field to a [team content type] node that references the home team for the game. Then I am trying to render this view in a block within the game node [Displays the home team's season schedule]
Thanks for any help.
Tim
Comment #19
gausarts commentedSorry if this is closed. But it's the nearest issue I have. I just don't want to hijack nor duplicate, only extend the question.
I managed to display views of the current user using this:
views_embed_view('status', 'block_1', $uid)
But I want to display the limit in that line as well, say to 1 or 3 nodes, while at the same I can have the same block with unlimited nodes display.
After reading the function views_embed_view in the module, and searching all around the world, I give up now, really.
I tried views_embed_view('status', 'block_1', $uid, 1) and views_embed_view('status', 'block_1', $uid, $limit = 1) and several blind break downs to no luck.
Please tell me if this is possible with that function to add the limit. If not how do I make it?
In the meantime, I have two options:
1. Two different blocks with each own Items to display.
2. Two different views with different Items to display.
But I considered both tedious. Any easier way?
Thanks.
Comment #20
deviantintegral commentedYou should just be able to do a theme override for your view. I haven't pulled up code, but I'm sure that you can do something like sizeof($view->rows) or whatever contains all of the nodes to theme. It shouldn't have anything to with embedding specifically.
--Andrew
Comment #21
mooffie commentedWhat's tedious in that? Just add another "Block" display to your view, and override its "item per page" option. Nothing tedious. Then pass 'block_2', or whatever, to views_embed_view().
You could try:
I haven't tried this, though. Expect typos. The "tedious" way would be the better choice for non-programmers.
Comment #22
gausarts commentedYou are right. Thanks for the light.
Comment #23
fit commentedI embed my view with this code:
But how can I style this view?
I created view and I putted it on my page but it looks awful - how can I style it?
Comment #24
bensnyder commented...using a view-[viewname}.]tpl.php template in your theme folder...
You could also wrap a
Comment #25
fit commentedHi,
I have problems with some divs that I dont need; some divs like:
and I dont need those.
I checked all my tpl.php files of my view and there is no divs like this - it can be that this divs are served with this 'default'
in this line
Edit: Added
<code>tags so the divs didn't get stripped by the input filter.Where I can style this default display of a view?
Comment #26
bensnyder commentedOk... here is the solution.
1) Go to your views modules directory (mine is in sites/all/modules/views/).
2) Open the "theme" directory (again, mine is sites/all/modules/views/theme/)
3) Copy any tpl.php's you need to you theme directory... for example: sites/all/themes/[your_theme_directory]
The main view template is views-view.tpl.php... and the others are special cases or sub-components...
4) Modify them till your heart is content. BUT, DO NOT modify the default tpl.php's in the views directory.... make sure you copy theme and THEN modify the copies.
::::::::::::::NOTE::::::::::::
Modifying, for example, the views-view.tpl.php will modify all views across your entire site by default. If you specifically wanted to modify a view called... say... stories-on-frontpage.... then you could create a template like so: views-view-stories-on-frontpage.tpl.php. Now, I'm GUESSING on the syntax... meaning I know that that IS the way to do it... but I don't know if the way I spelled/wrote views-view-stories-on....tpl.php is correct. Some research in the documentation should tell you... That should take about 15 minutes.
Need any more help?? Just ask! I'll answer what I can :)). But for now, I'm going to mark this as fixed.
Comment #27
bensnyder commentedI just looked at your "tracker" and saw your other posts... you want to have 2 columns on your home page?? Ok... here's how most drupalers would do it. I'm going to lay it out briefly and basically because I don't have a lot of time and you will learn more figuring it our yourself.. But here are some basic guidelines.
Modules:
---------------------------
Panels
Views
Note: Both of these are written by the aMaZinG merlinofchaos ;)
1) Create a Panel Node.
2) After you create the basic node (at this point it doesnt have to show any content)... Go to { Administer > Site Configuration > Site Information } and change "Default front page:" to point to that node.
3) Now, your home page will show the panel. I'm guessing you will have chosen a two column layout. So each of those columns need sorted lists of other nodes... right? Here's where views comes in.
4) Each column will have its own view. So make nodes that go in each, then add those nodes to the views you create. Then, add the views to the panel under the "Panel Content" tab on the panel page (in this case the front page). To get them to be available, check the box under { Administer > Panels > Views Panes}....
And walaaaa!
Now if you want to get even more crazy..... instead of assigning the Panel to be the home page, you can use the Front Page module http://drupal.org/project/front. You can embed the panel inside the front page that way....
Sorry.. I don't have any more time at the moment. I Hope this helped!!!
Comment #28
fit commentedpegleglax - I did that. All that.
But I still have some divs that are displaying on my page and I dont see them in those .tpl.php files.
I checked all my tpl files and I dont see those divs.
Can you tell me what mean that 'default' in view displaying?
Comment #29
bensnyder commentedplease copy/paste the HTML here so I can take a look at it... and comment on which divs are frustrating you
Comment #30
fit commenteddiv class="view-content"
div class="views-row-1 views-row-odd views-row-first views-row-last"
Those divs are frustrating me.
Comment #31
bensnyder commentedsites/all/modules/views/theme/views-view.tpl.php
It' like a cake. It's got layers.... Here you can see that $rows is a variable... so the [div class="views-row-1 views-row-odd views-row-first views-row-last"] layer is being generated in another theme template.
Here's what I suggest. Install the Devel module and enable Theme Developer. Use it like you would Firebug... and select that div, It will tell you what theme template is generating that div AND it will tell you which templates you can make to customize that div specifically.
;)
Comment #32
fit commentedThanks for your reply.
I've installed devel module - 6.x-1.12 - and it is not working properly.
When I checked 'Themer info' and I've selected div, any div from my page and it is not working, its loading, loading, loading and loading and I didnt get any informations.
I tried this several times and always loading and loading.
Comment #33
merlinofchaos commentedview-content is coming from views-view.tpl.php
views-row-* is coming from views-view-unformatted.tpl.php
Please note that extra divs aren't usually a problem. Unless you've got some really bad CSS they shouldn't do anything at all to your output except make the code a little bit bigger. So I'm not sure why you would be going to a lot of effort to find and eliminate them. Someday you may find you want them.
Comment #34
bensnyder commentedI agree with merlin. I didn't quite understand why you'd want to eliminate them... I mean really... It all comes down to how much of a ninja you are with CSS. More divs id's and classes is almost 99% of the time better because it really breaks the structure down into a logical format.
Comment #35
fit commentedI really dont need them and I dont love junk in my code.
Anyone know what is a problem with devel module?
Comment #36
merlinofchaos commentedThat's fine but why are you wasting other people's time on trivialities? If you're not good enough to remove the divs yourself, and they aren't causing any problems, then that's a totally inappropriate use of this issue queue.
And this is not the devel issue queue.
Comment #37
theabacus commentedsub
Comment #39
mitjaxp commentedthat's work but i'm using views slideshow filter and this slideshow not working ok when i'm embedded view
Comment #40
mitjaxp commentedComment #41
blackdog commentedmitjaxp: Please post a new issue with your question. Try the Views slideshow issue queue to see if anyone there knows more.
Comment #43
liquidcms commentedspent an hour trying to get this to work; then found this post.. doaahhh!!
figured i'd post my results for those stumbling upon this as well:
i was trying to add a block into the header of another view. wanted to insert in to 2 different views but with differences in each so i created a default and a block display.
this shows the 3 things i tried and the bottom one is the only one that worked:
hope this helps.
Comment #44
liquidcms commentedslight correction, the 3rd line, where i set the display, isn't needed for calling the preview method the way i do where i pass the display id.
Comment #45
merlinofchaos commentedThis probably would've worked:
Comment #46
liquidcms commentedcool, thanks, i'll try that next time.
Comment #47
tjb74 commentedWhen I use the code below in my node-tpl.php I am missing how it gets the argument from the url (I am using taxonomy terms as the argument, and in the url is ..content/taxonomy_term)
If I add the taxonomy term in array('taxonomy_term') the correct information is displayed, however I need that term passed from the url...
Apologies if this is a basic question or already documented but I have not found the answer. Thanks.
Comment #48
tjb74 commentedBy reading above I tried just using this...
If I use arg(0) or arg(1) all that is printed is the title and the comments on the node for the taxonomy... and none of the fields. If I use arg(2) or more all the fields for all the nodes of that content type are printed on the page...
I have themed my fields for the view with view.tp.php files, and it work on the view configuration page with the argument on love preview showing the right node.
Comment #49
SuperRookie commentedI'm trying to embed a table created in views in a node-tpl.php file. This snippet works:
But it doesn't display the information in the table form that is previewed in Views.
When I use this snippet:
I get this error:
"Parse error: syntax error, unexpected T_VARIABLE in /home/cg5748/public_html/swinefluretinalscan.com/enter/themes/garland/node-summarypage.tpl.php on line 24"
I can't find a way to embed the thing while preserving the table formatting. Please advise!
Comment #50
leovarg commentedhow to pass a filter or an argument?
Comment #51
Rob_Feature commentedI thought I understood all this but I just re-read all the comments above and now I'm confused:
In the answer to the original question of embedding views into nodes, merlinofchaos says (in comment #1) that we should use $views->execute_display() to embed the views. But, then in comment #13 he seems to contradict himself by saying never ever ever use execute_display() to embed a view... (and refers to views_embed_view as the proper method).
So, I think I'm missing some context here. Which code is right for embedding the view into a node and why is the other incorrect? Thanks for the clarity...
Comment #52
merlinofchaos commentedAt the time I wrote #1 things were a little different. execute_display() needs to be used only where the display was meant to be used, or you will get unexpected behavior.
Comment #53
brynbellomy commented[question deleted by virtue of being idiotic]
Comment #54
Silicon.Valet commentedThis is probably an imagecache issue, but I'll ask here as it was alluded to as a problem above. When using views_embed_view (or execute view for that matter) I'm not getting the same block that I see in the preview on the views page. I first assumed it was an order of module execution issue, but I've set my module weight rather high and still see the problem.
Specifically, I'm using imagecache and lightbox on a view that generates a grid of images. When in views preview, it works fine (or as a block). But when embedded, the lightbox markup is missing. I could put it back with theming, but it should be there in the first place.
Suggestions?
Comment #55
dawehnerDon't hijack issues.
Make a new one, i think the problem could be 1. wrong display select in preview or embed, missing js from lightbox2 because you do it in page.tpl.php
Comment #56
dravidian7 commentedi added this in to my node-content-type.tpl.php:
print views_embed_view('view_name','default',arg(1));
(my path was /node/nid )
worked great.
Comment #57
CccXxx commented@#43 - liquidcms
Thank you very much. Your example was the only one to work for me. ty ty
Comment #58
Marko B commentedCurrently if i use
$view = views_get_view('Banner_miss');
print $view->execute_display("block_1");
i only get Array returned, using this in node-something.tpl.php, is this still working or what is needed now to have view displayed?
Comment #59
merlinofchaos commentedWhen embedding a view, use $view->preview(), not $view->execute_display().
Comment #60
Rob T commentedThanks for posting this, liquidcms. I was having some trouble getting my block display view to show in a node.
Comment #61
RichieRich commentedI just can't get this to work. No matter what I replace 'default' with I always get the default view. For example, I'm trying to use a block which displays only 5 nodes here but I still get the default view:
I've tried all the variants above but nothing seems to work. I must be making a mistake somewhere.
Comment #62
dawehnerblock5 is not a valid display name. i guess it's block_5
Comment #63
BeaPower commentedWhere do I put these codes?
Comment #64
awm6392 commentedI've used the following code to embed my view:
However, now I would like to display each row of the view in a separate tab on the page. What code can I use to just embed a single row from a particular view, instead of just the whole view?
Comment #65
dawehnerThis is a total different question.
You need definitive quite some custom coding to achive this.
In general hijacking issues is not nice.
Comment #66
yaworsk commentedsubscribe
Comment #67
awm6392 commentedSorry. I gave it quite a bit of thought before posting and thought that the question was related enough to the original issue to be a part of this thread. I guess I was wrong, so I will post a new issue.
Comment #68
glennnz commentedI've tried all of these different options, and can only get the view content to display. The Title never shows...
Comment #69
glennnz commentedJust changing the status and version.
Comment #70
dawehnerThis depense on the display plugin you use. But i don't know one beside views attach which displays the title on the same region than the view.
Please don't hijack issues. Noone want's to read long issues with ten total different questions in it.
Comment #71
anne-pierre commentedthank you merlinofchaos. this worked for me. VIEWS is really great (once you get the hang of it)!
Comment #72
mossill commentedThank you my friend!
how does this method interact with drupal's basic caching ? Is it making a database call every time a view is requested ?
Comment #73
henriquefm commentedWhat about Drupal 7?
views_embed_view() seems to not exist anymore....
Comment #74
dawehnerWhy do you think this? It's definitive there
Comment #75
henriquefm commentedrookie mistake.... I was only looking in *.php files... thanks very much
Comment #76
RichieRich commentedI still can't embed any other display than the 'default' view. What exactly is the display ID? If I create a view which contains a block called 'i am a block' is this the displayID? Surely it can't be simply 'block' because it's possible to create multiple blocks within a single view.
I suspect the problem is that I'm not specifiying the correct ID...but where is the display ID found?
Comment #77
RichieRich commentedFound out how to identify the display ID. Thanks to this link:
http://www.pridedesign.ie/content/drupal-get-view-display-id
Comment #78
frozen10 commentedThanks fit #25..worked great. I tried some others, but couldn't get it to display! just what I needed. Now I have to style it.
Comment #79
tmwagner commentedFinally... a thread that addresses the issue of embedding a view that is accurate! The beauty of simplicity!
Comment #80
Jerome F commentedIf you're just trying to embed a view in a view as I was: http://drupal.org/project/views_field_view
Comment #81
rfiertek commentedHi All,
I've got the view embedded, but for some reason, my links do not work inside the view. The links work elsewhere on the page. Any ideas how to fix this or get around it?
Thanks,
Rob
Comment #82
kerios83 commentedview name is RELATED_CONTENT (machine name. And in first example u need to add what is inside view -> Advanced ->
Other -> Machine Name: block (block or page by default).
So we got view inside a module (d7) but how to print view title ?
Comment #83
manoloka commentedI'm trying to embed the a view in a view's footer.
All the examples here worked on nodes but none works in a view ???
how do I do that?
Comment #84
dunx commentedJust because it took me a few minutes to work it out...
The $args array is the args taken by the view itself. So, if you have a view that takes the nid as it's only arguement, from within your tpl file you can call
Comment #85
manoloka commentedNot sure if #84 was for me, if it was just let you know that doesn't work for me.
Thanks
Comment #86
manoloka commentedFinally I got it ... thanks to Kerios83 #82 post
I used this snippet
Thanks to everyone ... Great job guys :)
Comment #87
juanjo_vlc commentedwhat about setting custom template suggestions?
For example, I wan't to embbed a view, but use one row tpl or another based on some parameter. How can I do that?
Comment #88
marcopanichi commentedBlock from taxonomy view with title?
use this:
Comment #89
Anonymous (not verified) commentedIn comment #13 the module author himself states:
So why are people placing all these examples with execute_display?
Doesn't make any sense. Am I missing something?
Comment #90
thumbslinger commentedhere here. I'm wondering the same thing. Shouldn't need a module for this. Should just be the right syntax of a snippet of php.
Comment #90.0
thumbslinger commentedfixing typo