[support] retrieving key from selection list

Andreas Deininger adeininger at googlemail.com
Mon Nov 19 10:14:24 UTC 2007


Hi,

using CCK, I defined a field with a selection list inside one of my
custom content types.
In the allowed value list, I gave several key-label pairs in the
syntax "key|label."
Afterwards, I've defined a new view, filtering my custom content type
and providing a page of all instances as list view. I also themed the
field values in the list provided from the view by adding some code in
template.php of my theme.
So far so good. I basically achieved what I wanted. There is only one
thing left: I would like to get the key of the selected key-labal pair
in my themed list view.

Inside my template.php, the expression
<?php print ($node->field_unternehmenssparte[0][value]); ?>
provides the value of the field with the selection list (which
translates to the label from the selection list), but I don't know how
to get the key of the selection list.

my node looks like:

stdClass Object
(
  [nid] => 70
  [vid] => 70
...

  [field_unternehmenssparte] => Array
      (
          [0] => Array
              (
                  [value] => Automobilhersteller
              )

      )
...

I can't see a key there, only the value (=label) itself. Is there a
way to get hold of the key from the key|label pair?

Any hint is appreciated.

Thanks in advance

Andreas


More information about the support mailing list