I am trying to write code in the PHP Argument Code to provide the Page Node ID in a Block View Argument.
What reference do I need to use to get that Node ID? Is it a system/app level session variable? If so, what is variable name? Or do I need to have a user-defined session variable? If that is the case, where would I set it to have the Node ID value for the page?
I am an experienced programmer but a PHP newbie. A simple PHP code snippet example would be greatly appreciated.
I would imagine that passing a page nodeID argument to views in blocks for that page must be one of the most common requirements. Can anyone point me to documentation that covers that specific need?
Thanks in advance for any assistance.
Comments
Assuming you are on a node
Assuming you are on a node page, you can find it using the arg function: http://api.drupal.org/api/function/arg
if your URL is node/11 and you need 11, then it would be arg(1)
I have it working now - Thanks.
I went back and retried the NodeID from URL as default argument. I thought I had used that before and it did not work, but now it is working. I must have had something else checked at the same time.
How to call an argument for use in block?? PHP
I want to create a block that calls the same argument as the page is using.
So if the page is mypage.com/en/list-of/this, I want to retrieve "this" to use it in the block for: /some-other-list-of/this.
How is this done? Don't know or understand anything about PHP and after several years I know I never will. But something this simple but fundamental could (should) be explained somewhere just to help us eternal newbies on track. Some directly Drupal related practical PHP examples would definitely lower the starting barreer, but I didn't find anything in several days of searching, except this posting.
So I tried using the above mentioned
$node_id = arg(1);at the point of text in the (further plain HTML) block hoping it would produce "this" as seems to be used in some other programming languages, but it doesn't :(Doesn't PHP work that way or is it even possible to have a syntax error in this less-than-30-characters line of code?
tnx
I started with Drupal in 2007 and then my life got stuck...
path instead of id
I just realized I am not using /node/"number" but a pathalias, so I tried with $path but didn't work either... :(
In both cases simply nothing is produced.
I started with Drupal in 2007 and then my life got stuck...