I am creating a views handler for a field in my module and I would like to know the instance of the view that is being processed at runtime.
By "instance" I mean the view currently being rendered (not the view definition created by the user using my fields etc).
The problem I have is that to get Lightbox2 to group images from two different view instances on the same output page separately I need to be able to distinguish between them in some way so that I can tag the images associated with each separate view instance uniquely - otherwise lightbox groups all the images on the page together.
I hope this makes sense, it is a little esoteric!!
I can't see anything in the parameters to the view handler that will allow me to do this. I have considered trying to do it using an argument or by inserting something into the $query object but I can't see a solution.
Comments
Comment #1
merlinofchaos commentedviews_get_current_view() or global $current_view.
Comment #2
CoolDreamZ commentedThanks for the quick reply.
This didn't work for me as _views_load_view() caches the constructed view object (quite rightly!) and so $current_view always points to the same object.
Looking at the code I think what would do the trick is an ID property ("instance"?) on the view object that is incremented every time views_build_view() is called on the view.
I have made this a feature request. I have other ideas on how to solve the original problem.
Comment #3
gravit commentedI would like to also request this feature. Currently My need for this is CSS related. I am putting the name of the view on the body tag as a class.
Unfortunately, in my template's phptemplate_variables function for a "page" hook, the global $current_view variable seems to return the last view rendered. So if I have a Block setup that is being generated by the views module, and visit a page that is not an actual view but still has that block on it - then the $current_view variable will be the $view for the block, not the actual page render.
Comment #4
merlinofchaos commentedThis will not be fixed in Views 1.