How to call a block view from a page view and give it an argument

Events happening in the community are now at Drupal community events on www.drupal.org.
Sigal's picture

Hello,

Now I have a new brain teaser.

I have a page view that should call a block view.

The block view should get the node id from the page view as an argument.

In my page view, I have this code:

$block = module_invoke('views', 'block', 'view', 'availtext-block_1');
print $block['content'];

How can I send the node id from the page view to the block view?

I see I can put php code in the arguments section of the block view, but I couldn't find any help on what php code I should put there.

Can anyone point me to a help file or a web page where I can get help for this?

Thank you,

Sigal

Comments

Get arguments fromURL

Max_Headroom's picture

Hi Sigal
You get the node ID from the url. So in block view you use something like this:
$node = node_load(arg(2));

OK, I'm not 100% sure how to do it in a block view PHP argument section, but should be similar.

Quentin
www.webnthings.co.za

Quentin

The node id is not in the url

Sigal's picture

Hi Quentin,

Thank you but the node id is not in the url.

What happens is, I have a table view that displays list of nodes. Let's call it view A

Clicking on an item in this view calls a page view (view B) that displays the item's node, 1 in a page (I've created this view because I wanted the pager option, so the users can move from one node to another without having to go back to view A).

This page view calls a block view (view C), based on node_reference, and this block view needs the node id in order to display the right node_reference values.

So when I'm calling the view B from view A it is being called like this: http://judaicart/viewB

When you are inside view B, you have a pager, and then each page is being called: http://judaicart/viewB?page=x

View B is calling view C that needs the node id of each item in view B.

So as you can see, I don't have the node id in the url.

Hope that makes things a bit clearer.

Thanks,

Sigal

I found a module that might help me

Sigal's picture

Hi,

I found this module custom_pagers that is doing exactly what I need, puts a pager on a specific type of nodes.

My problem now is, that I have my custom node.tpl.php file called node-ketubah.tpl.php, so I don't see the pager on it, if I use the normal node.tpl.php file, the pager is there.

Can someone please help me and tell me how can I add the module to my custom node.tpl.php file?

Thank you,

Sigal

Blocks n Pages

SiteMaster.ServeLime.com_'s picture

Being a bit late to this conversation, maybe the following on the original intent...

Your use of the word "View" indicates that you are using the Views module?
What is unclear is what effect you are trying to achieve (Use Case description)
Maybe a bit of clarity/context on the effect you are trying to achieve might help. ;)

  1. If you are looking for a way to display a Block in a Page (ember in other content), there is a module that does that (can't remember the name unfortunately. search on "link"+...).

  2. If you have related content which you want to show together, then the NodeFamily module might be what you are looking for.

  3. The Contemplate Module can be used to theme blocks.

  4. You can achieve a multi-page effect by inserting a Page Break in your content.

  5. The PageRoute Module can give you control of a sequence of content to be displayed.

  6. On the Custom tpl file - Have a look to see if you have not perhaps removed something from the standard node tpl file.

As per the above comment, please start by detailing the effect you want. ;)

I always follow this following process:
Requirement (clear on behavior/effect) -> Design (Solution Choices: module options / code) -> Implement (tech)

Thank you

Sigal's picture

Hi,

Thank you very much for the advise on how to write a help request, I always get confused with my own words, and your way helps a lot :)

Besides that, I thought I explained everything in my post to Quentin, but I guess I wasn't clear enough.

Anyway, I found a solution, I'm using the custome_pager module, and somewhere I found that I can add it to my custom template by adding this line:

<?php
print $node->content['custom_pager_bottom'][1]['#value']
?>

This was not clear to me since when I did print_r($node->content); I didn't see the custom_pager_bottom variable, I see it as a class not as a variable. But, it appears it is there even if you don't see it.

Thank you,

Sigal

South Africa

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: