[support] retrieving key from selection list

Greg Holsclaw Greg.Holsclaw at trouvemedia.com
Mon Nov 19 18:45:40 UTC 2007


Did you explicitly define key|value pairs in the CCK definition, or did
you just place values in. For my site, I did place key|value in the CCK
definition and I get

    [field_required_tools] => Array
        (
            [0] => Array
                (
                    [value] => 0
                    [view] => No
                )

        )

I believe if you just placed a list of values, it will not assign keys.
Or we are using different versions of CCK.

Greg

-----Original Message-----
From: support-bounces at drupal.org [mailto:support-bounces at drupal.org] On
Behalf Of Andreas Deininger
Sent: Monday, November 19, 2007 2:14 AM
To: support at drupal.org
Subject: [support] retrieving key from selection list

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
-- 
[ Drupal support list | http://lists.drupal.org/ ]


More information about the support mailing list