Sorry if this question is too obvious, I need to load the current node from display suite and then execute this php code:


$project = node_load(5);

foreach ($project->field_gallery['und'] as $val ) {
  echo '<img src="' . $val['filename']  . '">';


In display suite I tried:

$project = node_load($nid);


$project = $entity->nid;

I also tried the same within a block, and it failed. It only works when I set a static id as node_load(5).

Please, can I get the answer how to load the node from display suite custom field and from a simple block?

Edit: I'm adding a custom field to display suite from this url:
Structure > Display Suite > Fields > Add a code field.

1 Answer 1


You can load the node id from node page using arg function...

Returns a component of the current Drupal path.

When viewing a page at the path "admin/structure/types", for example, arg(0) returns "admin", arg(1) returns "structure", and arg(2) returns "types".

node pages always has path 'node/nid' so arg(1) gives node id...

$nid = arg(1);
$node = node_load($nid);
  • Thank you, it works from block. Can you suggest how to get it to work from display suite? May 15, 2014 at 3:48
  • Regarding "how to load the node from display suite custom field", can you please explain where you are writing code ? What did you try regarding above ? Can you update your question with more details ?
    – Anil Sagar
    May 15, 2014 at 4:35
  • Sure. I updated my question. I tried it with $project = $entity->nid; May 15, 2014 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.