Hello,

In one of my blocks, I use the function node_load().

I see a field with its suffix and in the proper format.

The code I use:

<?php
print $node->field_cylindree[0]['value'];
?>

Example 1:
Result:
50.0
Desired result:
50 cm3

Example 2:
Result:
49.7
Desired result:
49.7 cm3

Thank you in advance for your help!

Comments

markus_petrux’s picture

Category: task » support
Status: Active » Fixed

If you want to use the prefix/suffix defined in field settings, the you need to use content_fields() function to retrive the $field information, as in the example that we already saw here: #637636: How to print the field label in node templates.

The prefix/suffix settings are there, just use var_dump($field) or equivalent to figure out the structure of the $field array returned by content_fields().

Clément’s picture

Thank you for your reply.

I do not understand how to use the content_fields()

I tried like this but without success:

$field = content_fields('field_puissance', $node->type);
print check_plain($field['widget']['suffix']);

I also looked at the link but it does not help me.
Is this you could explain how this function works or give me a link that explains in detail how it works?

markus_petrux’s picture

You need to explore the contents of the $field array returned by content_fields(). I prefer to help you learn how to fish, rather than giving you this particular fish, so please re-read my second statement in #1.

$field = content_fields('field_puissance', $node->type);
print '<pre>$field: '. check_plain(var_export($field, TRUE)) .'</pre>';

Now, see what the $field array contains. This should help you figure out how to resolve other things that you may need to do.

Clément’s picture

Thank you very much for your response.

These you should put (for suffix):

<?php
$field = content_fields('field_puissance', $node->type);
print check_plain($field['suffix']);
?>

You're right not giving me the answer because it would not have served for more. Thanks to your code, I can see the whole picture and thus understand what to do. It will make me much service for more ...

Another big thank you!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.