Hi friends,

I need to present node id and some field values in teaser content. Have installed DS module and activated it. Added a code field. Codes below are being used to display field values if node id is there.

$node = node_load($nid); 
print $node->title; 


$node needs to be replaced with node id. I need a code to display node id in code field. Is there php variables or replacement patterns available for code field in DS module ?

Comments

nevets’s picture

I believe it's $entity->nid (the comment below the box has the variable name for the object).

sumancool.jb’s picture

The replacement pattern for field values were given below with a heading
Token
Didn't notice it.
The replacement for node id is [node:nid].

bartolo.dileo’s picture

hi to all,

i have the same problem...I want to use the NID to check if the current node has a certain value for a field, but I can not read it.

CODE:

$nid=???????????????????????????????
$node = node_load($nid);
if ($node->my_field[LANGUAGE_NONE][0]['value'] == 'value') { ... }

if i put a fixed value for $nid var, the code work very well, but i want the current node nid.

you can help me??

ajlow’s picture

I think you may had set the Text Format dropdown to "PHP code". You need to keep it as "Display Suite code".

In "Display Suite code" mode, you have the access to the $entity object. $entity is not available in "PHP code" mode.

Nicolas Bouteille’s picture

soulston’s picture

This is more like what you would want. You could perform this in preprocess and then create a custom variable to output in your tpl or this could go in the node.tpl but it's not the best option.

if ((arg(0) == 'node') && (is_numeric(arg(1)))) { 
  $node = node_load(arg(1));
  $name_of_field = field_get_items($node, 'name_of_field');

  if (!empty($name_of_field)) {
    // Do something...
  }
}


VVS’s picture

Set checkbox "User token" and add token [node:nid].