1

I have a custom field that is an entity reference, when using

print render($content['field_call_to_action_1']);

in a content type template it prints out the title Call to Action 1, and the Title of the content that the entity reference is linked too.

How can I just get it to print out the NID instead?

Thanks for your time!

3

$content is to be rendered and obeys what you have set in node(other other entity) type's Display Settings (Administer > Structure >Content Types).

What you should use is, $node object.

<pre>
<?php
print_r($node);
?>
</pre>

Now you will see a nicely formatted information of $node object which also has the NID you want.

You will be able to access it with this:

$node->field_call_to_action_1['und'][0]['target_id']

Quick hint:If you are trying to build a URL link from this value, have a look at url() and l() functions!

  • 1
    I don't know is it just my case, but it didn't worked for me. I used 'target_id' instead of 'nid' and worked fine. – AlessMascherpa Jan 9 '13 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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