Views is a great module but it seems that it is "too" helpful for me in a couple of cases. I am trying to create views that display the Key Value of CCK fields. I would also like to create CSV Downloads that download the Key value and not the label. I have searched documentation and the forums on and off for several weeks trying to find something on this and have not had any luck.

Basically, I have several CCK fields that use a Key|Label format for Allowed Values. The Labels are great with our general web users but from an administrative view point I need to just see the Key Value. For one thing a Key Value of 'A' takes up a lot less room in a view than a 20+ character label. The label for Key "A" will change each year but from my view point. I just need to see A.

I have played with settings in CCK and found nothing that changes the behavior of views in this regard. In a node I found that ..fieldname['value'] displays the Key while ..fieldname['view'] displays the label but I have not found anyway to tweak Views.

So.. Is there some way to have the Key Value displayed in lieu of the Label Value in Views?

Thanks

Charles

Comments

kaakuu’s picture

Seems no by default BUT probably you can add Global text which can be as short as you wish.

techypaul’s picture

Hi,

Did you work out how to do this? I have exact same problem, the labels are really long but I have nice simple keys for admin use.

Thanks,
Paul.

canesWin’s picture

This seems like a feature that should be readily available. I'm wanting to rewrite a field to link in an image from the filesystem using the key value of a select list. Something link Only local images are allowed.

canesWin’s picture

For those of you looking for a workaround, use the Views CustomField module and pluck the value out of the $data array: http://drupal.org/project/views_customfield

alexanderevans’s picture

i've faced this a year ago, and i remember doing something similar to 'canesWin'. This should work.

karljohann’s picture

I'm also trying to figure this out, how would this be done with customfield?

thinkingcap’s picture

You can do this with the Custom Formatters module. http://drupal.org/project/custom_formatters

1. After you install the module, go to Site Configuration > Customer Formatters and create a new custom formatter. I called my 'Raw select key'.

2. Configure as follows:
Field type: text
HTML: [raw]
Click Save.

3. Edit the View and under the Fields section, click the relevant CCK field and change the Format to 'Custom: Raw Select Key'.

That should do it. A very elegant solution.

iparsin’s picture

I confirm this solution works very well. Thank you so much.

carl.ben’s picture

that was very helpful

greta_drupal’s picture

Hmmm. Just displayed the cck field token on view. Didn't convert. Basic editor. No WYSIWYG or input format options.

george.plescan’s picture

I tried doing this on Drupal 7 but I didn't see anything RAW in the tokens ...
And the field type shouldn't be list (text) ?

EKM’s picture

Worked for me... but turned out to be really slow when going through 100 rows. Render time went from 700 ms to 3000ms. If you only want to go through a few iterations, it should be fine though.

aganz’s picture

I second that, what is an easy and good way to achieve that in Drupal 7 / Views 3

lufecir’s picture

In case someone might still be wondering how to do this in Drupal 7, here is how I did it using default views3 capabilities:
*) In the 'Rewrite results' section of your field,
-) check the box 'Rewrite the output...'
-) and set as value [<your_field_name>-value] (you can find allowed replacement values in the list below the input field)
*) In the 'Style settings' section of your field,
-) check the box 'Customize field HTML'
-) and select 'None' for HTML element

And then field->content will return the key of the selected value.

Cwiggo’s picture

This isn't working for me. I've added the field. Below added another one, then done the steps that you have stated. But within the rewrite results section. The field does not appear in the replacement values. Do you know a solution? Thanks.

kerby70’s picture

Drupal 7 Views 3.0 appears to have this available on screen labeled formatter just under the exclude from display setting.