Hi!

I'm a beginer in php studying, so I ask anybody please help me.

I have created a gmap style block view and I want to show on that map some locations depends on current node.

As I understood in Default argument type: "PHP argument code" we should operate with parameters of currents page (in my case it is a node with a path - node\%) and then return one of such parameters as an argument. Am I right ?

If I'm right my question is:
Is there any possibility to get parameters of current node ( node type, node term, node user and so on) to operate with them in Default argument type: "PHP argument code" and then return as parameter?

Thank you for any advice!

Comments

nevets’s picture

Yes, pick "Node: nid" as the argument type and on the setting form pick the appropriate options. With view 2 no PHP code is needed.
Basic setting for "Node: nid" for block style view

  • Set 'Action to take if argument is not present' to 'Provide default argument'
  • Set 'Default argument type' to 'Node ID from URL'
  • Set 'Validator' to 'Node'
  • Set 'Types' to the appropriate type(s)
mas_master’s picture

Thank you, nevets!

I know such method.
Actually I didn't formulate my question well:
Is there any possibility to get parameters of current node ( node type, node term, node user and so on) by using php code in "PHP argument code", to operate with them and then return as ARGUMENT?

It would be great if I had some examples of PHP code usage in Default argument type: PHP Code. So that I could understand the opportunities of that feature.

nevets’s picture

Yes, there is the possibility though it depends on what you want to do. To start with there needs to be an argument type that corresponds to what you want to return (For example "Node: Type"). So using "Node: Type" as an example

  • Set 'Action to take if argument is not present' to 'Provide default argument'
  • Set 'Default argument type' to 'PHP Code'
  • Set 'PHP argument code
    if ( arg(0) == 'node' && is_numeric(arg(1)) )  {
      $node = node_load(arg(1));
      return  $node->title;
    }
    

In general the line return $node->title; would need to reflect the argument type selected.

mas_master’s picture

This is exactly what I needed. Thank you!

Anonymous’s picture

This is exactly what I needed to display contact information on the side of my client's website, relative to the node which had the general information about the building.

Awesome stuff.

soumyadas’s picture

You have explained it very clearly.