By mlondon77 on
I'd like to use the active node in the content to define a variable which I can then use for a SQL query. I'm trying to define the variable in the following fashion, but it just comes up blank.
$page = $node->nid;
echo $page;
Note I am trying to use this code in a block and not in my template. In the template, it works just fine.
Any suggestions? I've searched and searched the forums, but can't find a solution.
Thanks in advance for any suggestions.
Regards,
Michael
Comments
There is no global node so
There is no global node so assuming this is meant for pages that display a single node (node/{nid}), you would first need to get the node, though in your case you only need the node id (nid) so something like this should help
Thanks!
Thanks so much! It worked like a charm.
If you have an extra second, just out of curiosity, what is the arg function?
Thanks again.
The arg() function returns
The arg() function returns the unaliased parts of the path. So if your path was 'node/47/edit', arg(0) would return 'node', arg(1) would return '47' and arg(2) would return 'edit'.
Thanks
Thanks for the explanation. I'm sure it'll come in handy in the future.