I've got a situation where I need a block to know about the contents of the node being displayed.
I've got a block with custom code which starts,
if ( arg(0) == 'node' && is_numeric(arg(1)) ) { $node = node_load(arg(1));
That works for when the node is displaying on its own page.
But my problem is that I am displaying the node using Views and not on its own page. The reason I am doing this is that that the one node that displays in the view dynamically changes depending on the $node->created time. The view works perfect for this; one URL, dynamic content.
But I need the block to have access to the node object of the one node currently displaying in the View.
What is coming to mind is to run the same query in the block that the view is running to get the $nid and do the node_load off of that. But I thought there was an easier way. Or do I have access to the View object?
Thanks for your suggestions,
Shai
You may consider views_get_view_result()
A bit of a tangent, but the Panels module is great at solving use cases such as these http://drupal.org/project/panels
On Thu, Apr 14, 2011 at 10:56 PM, Shai Gluskin shai@content2zero.comwrote:
I've got a situation where I need a block to know about the contents of the node being displayed.
I've got a block with custom code which starts,
if ( arg(0) == 'node' && is_numeric(arg(1)) ) { $node = node_load(arg(1));
That works for when the node is displaying on its own page.
But my problem is that I am displaying the node using Views and not on its own page. The reason I am doing this is that that the one node that displays in the view dynamically changes depending on the $node->created time. The view works perfect for this; one URL, dynamic content.
But I need the block to have access to the node object of the one node currently displaying in the View.
What is coming to mind is to run the same query in the block that the view is running to get the $nid and do the node_load off of that. But I thought there was an easier way. Or do I have access to the View object?
Thanks for your suggestions,
Shai
-- [ Drupal support list | http://lists.drupal.org/ ]
I think Panels can do this with contexts. You don’t really need a block at that point.
I’ve heard that Contexts can do similar stuff, too, but I’ve never used it.
Joel
From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Shai Gluskin Sent: Thursday, April 14, 2011 11:56 PM To: support@drupal.org Subject: [support] Need Help with A Block Knowing Info About First Node in aView
I've got a situation where I need a block to know about the contents of the node being displayed.
I've got a block with custom code which starts,
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
$node = node_load(arg(1));
That works for when the node is displaying on its own page.
But my problem is that I am displaying the node using Views and not on its own page. The reason I am doing this is that that the one node that displays in the view dynamically changes depending on the $node->created time. The view works perfect for this; one URL, dynamic content.
But I need the block to have access to the node object of the one node currently displaying in the View.
What is coming to mind is to run the same query in the block that the view is running to get the $nid and do the node_load off of that. But I thought there was an easier way. Or do I have access to the View object?
Thanks for your suggestions,
Shai
Would probably need to know a bit more about the view... Are there other nodes being displayed in the view? I'm assuming not or that there is something unique about your node? Or that your context in your block changes for any of the items in your view? Or do you mean that sometimes the view shows your node and when it does your block needs to know about it?
My first thought is just have another block in your view that doesn't show any fields, but still returns the same nids as your main view and put your php code in there.
Actually, just read the subject line about the first node... definitely use another block display in your current view. Limit it to return just the first item. Add what you need.
On 6:59 AM, Shai Gluskin wrote:
I've got a situation where I need a block to know about the contents of the node being displayed.
I've got a block with custom code which starts,
if ( arg(0) == 'node' && is_numeric(arg(1)) ) { $node = node_load(arg(1));
That works for when the node is displaying on its own page.
But my problem is that I am displaying the node using Views and not on its own page. The reason I am doing this is that that the one node that displays in the view dynamically changes depending on the $node->created time. The view works perfect for this; one URL, dynamic content.
But I need the block to have access to the node object of the one node currently displaying in the View.
What is coming to mind is to run the same query in the block that the view is running to get the $nid and do the node_load off of that. But I thought there was an easier way. Or do I have access to the View object?
Thanks for your suggestions,
Shai