Article

How to print product field in Drupal 7 template (TPL file) in Drupal Commerce

Normally, in printing fields in Drupal 7 for the usual nodes, we use:

<?php print render($content['field_phone']); ?>

Now, we have a rather similar but different format for Drupal Commerce products display. You may use below "Commerce" equivalent of what is normally done for the usual Drupal nodes. This is assuming you want a field item within your product nodes printed or displayed on your template or TPL file:

<?php print render($content['product:field_description']); ?>

This will display both field label and field item value alongside. To hide the label and display only the value, you may need to go to the product content type's Manage Display and set Label to Hidden, or maybe apply to the label the necessary CSS display:none to hide it if this is applicable and doable.

After uploading tpl file, do not forget to flush cache, then reload page to check and view the changes.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.