1

I have added blocks to my custom module. A same block should be displayed in two pages. I have to display the field $node->field_tag['und']['0']['value']; in my block.

$nid = explode("/", $_GET['q']);
$node = node_load($nid[1]);

I got the node id by this. When it goes to another url it is not loading. So how can I get the nid in the block_view theme page without using the url?

  • You mean to say that, you have programmatically created a NEW BLOCK. And you are showing this BLOCK in 2 different pages. In one of the page you will get the NID and by using NID you will load a TAG field. But in another page your not able to get the NID to load TAG field? – inizio Aug 13 '13 at 21:08
  • yes @inizio that is my issue... – Ajmal Aug 14 '13 at 4:39
  • Can you able to pass nid PARAMETER in the URL? – inizio Aug 14 '13 at 5:38
  • No i'm getting the value of nid only from the url. so i cant pass it to the another page..... – Ajmal Aug 14 '13 at 6:32
2

You want menu_get_object() to obtain the node object when visiting a node page.

| improve this answer | |
  • no it not works for me – Ajmal Aug 13 '13 at 12:19
  • menu_get_object() seems the recommended way to go. Why is it not working for you? – Kari Kääriäinen Aug 13 '13 at 17:20
0

You can also do this (show a node's field in a block on only two pages) without a custom module. Make a block view showing this field. On the block configuration page make it display only on the two URLs that you want.

| improve this answer | |
  • but I need the nid for loading some of the contents the block requires – Ajmal Aug 13 '13 at 12:19
  • Do you mean you need some content from the node you need to process rather than display the way the Views module can? Can you elaborate? – Kari Kääriäinen Aug 13 '13 at 17:11
  • yes I have to load the node there in order to display some contents of the node in to the block. As now I'm getting it from url. it is not same as that of another page – Ajmal Aug 14 '13 at 4:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.