Hello,

I can not display the name of the label.

I tried like this but it does not work (NULL):

<?php
print $node->field_type_moteur[0]['label'];
print $node->field_type_moteur[0]['label_name'];
print $node->field_type_moteur[0]['label_title'];
?>

Thank you for your help!

Comments

markus_petrux’s picture

Category: task » support
Status: Active » Postponed (maintainer needs more info)

Where are you trying to executed that code?

markus_petrux’s picture

Component: CCK in core » General
Clément’s picture

In my_block.tpl.php

My module:

<?php
// $Id$

/**
* Permissions du module
* @return array Tableau de permissions valides pour le module helloworld
*/
function modeles_2r_perm() {
  return array('access modeles_2r content');
} // function mon_module_perm()

/**
* Implémentation de hook_block
*/
function modeles_2r_block($op = 'list', $delta = 0, $edit = array ()) {
   switch($op) {
      case 'list':
         return array('modeles_2r_presentation_block'=>array('info'=>'Modeles 2R: Block Presentation'), 'modeles_2r_fiche_technique_block'=>array('info'=>'Modeles 2R: Block Fiche Technique'), 'modeles_2r_coloris_block'=>array('info'=>'Modeles 2R: Block Coloris'));
      case 'view': {
         if ($delta=='modeles_2r_presentation_block') {
               return array(
               		'subject'=>'Presentation du modele',
               		'content'=>theme('modeles_2r_presentation_block', $node));

         }
         if ($delta=='modeles_2r_fiche_technique_block') {
               return array(
                    'subject'=>'Fiche technique du modele',
                    'content'=>theme('modeles_2r_fiche_technique_block', $node));
		 }
         if ($delta=='modeles_2r_coloris_block') {
               return array(
                    'subject'=>'Coloris disponible pour ce modele',
                    'content'=>theme('modeles_2r_coloris_block', $node));
		 }		 
      }
   }
}

function modeles_2r_preprocess(&$variables) {
			$node = node_load(arg(1));
			$variables['node'] = $node;
}


function modeles_2r_theme($existing, $type, $theme, $path) {
   return array(
      'modeles_2r_presentation_block' => array(
          'arguments' => array('node'),
          'template' => 'modeles_2r_presentation_block'),
      'modeles_2r_fiche_technique_block' => array(
          'arguments' => array('node'),
          'template' => 'modeles_2r_fiche_technique_block'),
      'modeles_2r_coloris_block' => array(
          'arguments' => array('node'),
          'template' => 'modeles_2r_coloris_block')
		  );
}
?>
markus_petrux’s picture

Status: Postponed (maintainer needs more info) » Fixed

Ah, ok. So, you need to read field information using CCK APIs. Try:

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

[EDITED] added check_plain() to the example above. Oops!

Clément’s picture

Thank you for your professionalism and your speed!!!

Now it works.

It's just a little bit annoying because I must display the name of 50 labels ...

I'll try to make it simpler thing.

markus_petrux’s picture

Title: show field name » How to print the field label in node templates

Better title.

Status: Fixed » Closed (fixed)

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

spacereactor’s picture

I try the above

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

and only work with default language, but the label remain the same language when i switch to other language. I have already translate it to other languages for my label.

I trying to make a multi language site with custom node-content-type.tpl.php theme. Any help?

spacereactor’s picture

ok solve it by change check_plain() to t()

$field = content_fields('field_name', $node->type);
print t($field['widget']['label']);

But i need help to add in GROUP label. anyone?

beckyjohnson’s picture

How would you add a space between the label and the field using php?

I did this:

<?php $field = content_fields('field_book_category', $node->type);
print t($field['widget']['label']);
echo '&nbsp;';
print $node->field_book_category[0] ['view'] ?>

But it didn't seem very elegant.

I tried this too:

<?php $field = content_fields('field_book_category', $node->type);
echo 't($field['widget']['label'])' . '$node->field_book_category[0] ['view']' ?>
 

and I just get php errors.

same with

<?php $field = content_fields('field_book_category', $node->type);
echo 't($field['widget']['label']);' . '$node->field_book_category[0] ['view']' ?>
 

and

<?php $field = content_fields('field_book_category', $node->type);
print 't($field['widget']['label']);' . '$node->field_book_category[0] ['view']' ?>
 

Becky