WHat i really mean here is there any modules or examples of php blocks that "know" what node it's looking at, and can pull up related content? Let's say for example I have a node about cats, and i want to have a bunch of cat photos associasted to that node, and to show up in a block, how would i do this?

It seems that blocks are defined from the get-go to be quite separate from nodes, but visually this is often not the case, where sidebar content supplements node content.

I hope this makes some sense, if anybody has done this before or have ideas, let me know.

Comments

ShavenYak’s picture

When you configure a block, you can specify that it only appears at certain URLs within Drupal. So, you could create a block with cat photos, and specify to only show it on node/4, which would be your node about cats. Then, you could create another block with dog photos, and specify that it only gets shown on node/5 (about dogs, obviously).

This trick is also handy if you want to have specific menus show up when different areas of the site are being browsed. It really works well if you use the pathauto.module to build URL aliases by category or node type.

Emiliano’s picture

Hi!

sidecontent module might help you guys:

http://drupal.org/project/sidecontent

Regards,
Emiliano.
http://www.novayork.com

venkat-rk’s picture

You have company:(

I posted a somewhat similar problem in the context of presenting member information where I *had* to create a vocabulary with 200+ terms just to give a listing page for members and because there wasn't an easier way to pull up custom info in blocks on the 'user' pages. Sure, I could have used php snippets, but that approach doesn't scale well- I would have been lost in a maze of custom blocks, their placement and paths.

I think it requires a module that will automate the process. Just occurred to me- do you think the views module will help?

nevets’s picture

I wrote a module for a client where they wanted information related to the current content to show in a block.

The challange, blocks do not know by default the content being shown in the "main" part of the page. In this case the content and the block could be generated by the module so I used the following solution. In the hook for view the content, if the content was being displayed by it's self ($page == TRUE), I use a global variable to record the node viewed. The block code then uses the global variable to do it's thing. Note this only works because the code to build the center is called before the code to build blocks.

In the case where the block buildiing code is in a different module I would use the nodeapi hook and do something similiar when the $op was 'view'.

luyendao’s picture

That sounds like a good way to go nevets - i'm not a developer, but from an interface point of view, and usability, it'd be great if there was a way to make associations between nodes and blocks. Often blocks are just sub-sets of a node, and the way drupal works right now, on a large content site you might have to manage a hundred blocks manually, and set their relationships one by one.

I'm already at 30 or so, and the site hasn't even launched yet. So ideally, when you edit a node, you could also associate blocks that will be rendered in a batch sort of way, as opposed to editing block by block.

Appreciate all the comments, and thanks for the module link Emiliano, I will definitely check it out!

divrom’s picture

Hi nevets.

That sounds like a great idea - and I don't want to blag code that someone else has paid for - but I haven't got a clue what you're talking about! ;-)

Is there any chance you can post some example code, or point me somewhere else?

Cheers.

develcuy’s picture

Here is a solution: http://drupal.org/project/block_assign
--
(3 John 1:2) Dear friend, I pray that you may enjoy good health and that all may go well with you, even as your soul is getting along well.