By DWB Internet on
A short question to which I cannot seem to find the answer:
I defined a block within my module. This block is displayed in every page but its contents depend on the node currently being diplayed (in page view).
How can I (from within my module) check which node is currently being displayed in the page?
Thanks a lot, Emdo
Comments
If you are talking about the
If you are talking about the node displayed when viewing pages like node/{nid} you can get the node like this
[Edit to fix function name]
Thanks Nevets, that's
Thanks Nevets, that's exactly what I was looking for.
is_numeric
correction:
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {not:
if ( arg(0) == 'node' && s_numeric(arg(1)) ) {'(Òvó)
Better solution in Drupal 6
Hi,
I answer to this old thread because it is rather well-positioned in google search results.
Since D6 there is a much better solution for this problem. You can get the current $node object without loading it from the database with:
Using menu_get_object() in a
Using menu_get_object() in a block did not work for me. For example, the following code prints nothing:
Is there something else that has to be done to make it available from within a block?
$node will only be set if
$node will only be set if viewing a single node, ie unaliased path of node/{nid}