I have a node reference field which I can output using echo render( $content['field_link'] );
This is fine for one situation in the node but I also need to output just the path of that node. I can output it using echo $node->field_link['und'][0]['node']->uri['path'] but I don’t want to hard code the ‘und’ and ‘0’ array keys in. There is presumably a way to do it with render().
If someone could point me in the right direction that’d be great, thanks.
Ben
You can’t do it with
renderbut you don’t need to hard code the language code, you can get it from the global variables:You won’t be able to get around using the
0key though, all fields are stored with the potential to be multiple so you will always need to ‘pick’ which element you want to get.If the cardinality of your field is 1, you can always assume that the element you’re looking is for is at
field_link[$language->language][0]. If not you’d need to run through each element in theundarray and decide which one to display.EDIT
You can also use the
LANGUAGE_NONEconstant (which will generally return ‘und’, but either way wil be the correct language code for the default content).