Closed (fixed)
Project:
Views (for Drupal 7)
Version:
4.7.x-1.x-dev
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
9 May 2006 at 18:15 UTC
Updated:
24 May 2006 at 02:15 UTC
Is it possible to use the argument field in embedded views or blocks? I want to embed some views based on the og_nid field from the og_views module, but I don't know how I can define the argument if I'm not using a page, but embedding the view within another page.
Comments
Comment #1
yched commentedIf you embed your view using something like :
you can set the $view_arg parameter manually just before that, e.g :
Just make sure you provide the arguments in the same order as in the view definition
Comment #2
jasonwhat commentedthanks for the tip. I tried this code but am not getting the same view as when I use the url. The only arg involved is the OG_nid which is just the node id of the organic group.
Do you see anything wrong in this? 557 is the ID and "groupnews" is the name of the view.
Comment #3
yched commentedI don't really know what can be wrong...
Can you be more specific about that ?
Comment #4
jasonwhat commentedIf I use a url and go to a page using arg. 557 in the url it works fine. If I try to get the same output using the code and embedding it in a page it just comes up blank.
Comment #5
yched commentedblank ?
Sorry if that sounds offending, but are you sure you are really outputting the content of $output ? :-)
Try setting the "default" behaviour for your argument as "Display all values", and run your code with an empty $view_args array. If you're still getting a blank page, I'd say the output doesn't make it to the page, since your view obviously is not empty...
Comment #6
yched commentedYou could also try to empty drupal's cache table.
That's often a "magical" solution when something that should work doesn't...
Comment #7
jasonwhat commenteddoesn't my code need some sort of "print output" after the last line that I have now?
Comment #8
jasonwhat commentedYep, the finish code looks like this:
I just forgot print output. If this example is correct this should definately go into the handbook.
Comment #9
yched commentedI guess your code is a snippet you enter in a "php" textarea in a 'page' node ?
You should try
return $output;instead ofprint $output;It should work, and it's cleaner (probably a matter of taste, though :-) )
Comment #10
merlinofchaos commentedThanks, yched, for supporting this!
Comment #11
jasonwhat commentedthanks for the help. I see a lot of uses for this. By using Drupals arg functions a user can pull arguments out of standard drupal urls (like taxonomy/term/3 or node/51) and pass them to a view. I could see this being a good way to layout things like taxonomy pages with separate node types in separate columns on the page, or in my case on an organic group homepage.
Comment #12
merlinofchaos commentedThere is a field, the PHP args field I think, that you can put PHP code into and actually directly modify the args of the view. WHen the API docs get updated, an example of this will be included.
Comment #13
yched commentedIn fact, that "Arguments handling code" works even with "block enabled" views - meaning that arguments are parsed from the url not only when you are on the url of a "page" view, but also when rendering any views-exported blocks (am I being confuse ?)
I'm not 100% sure though whether that's a real "feature" you can rely on, or a permissive behaviour that will get fixed some day.
Anyway, views.module is sooo rich and surprising, that's sometimes dizzying :-)
Comment #14
merlinofchaos commentedNo, block views don't receive any arguments; unless the php arg snippet does the parsing for you.
Comment #15
(not verified) commented