Tip 1: with list fields, quickly display what you really want to display

Now, to the juicy stuff.

Suppose you have a list field, named “field_shipping_type”, with two options:

exp|Express shipping
regular|Regular shipping

If you use:

<?php
print $node->field_shipping_type->value();
?>

It will print the word “exp”. But I want to display the human-readable value. How to do that? Quick!

<?php
print $node->field_shipping_type->label();
?>

Tip 2: with any kind of field, display its label

Suppose I am, again, with a bunch of fields, and I'm trying to display them in a page. I need the field’s label to show it. With the magical function ->info() of the wrappers, I can do just that:

<?php
print $node->field_shipping_type->info()[‘label’];
?>

Neat, uh? There are a few more things hidden in this ->info(). In fact, all the information concerning the field is there. You may find it useful someday. 

Image credits:  https://www.flickr.com/photos/danielygo/11377205686

Leave a comment

Can't you use ->label() too?

Read more

A very brief introduction on Entity Metadata Wrappers