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
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@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Andreas Deininger Sent: Monday, November 19, 2007 2:14 AM To: support@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
2007/11/19, Greg Holsclaw Greg.Holsclaw@trouvemedia.com:
Did you explicitly define key|value pairs in the CCK definition,
Yes.
or did you just place values in.
No.
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 ) )
That's exactly what I'm looking for and would solve my problem.
I believe if you just placed a list of values, it will not assign keys. Or we are using different versions of CCK.
I'm using Drupal 5.3 (with PostgreSQL as database backend), Content module 5.x-1.6-1 and Views module 5.x-1.6. I think these are the latest versions.
Does anyone have an idea why [view] is not showing up in my array?
Thanks in advance
Andreas