By Rosamunda on
Hello there!
I´ve been reading some stuff about themeing cck fields (ie. this very good 5.x explanation. I didn´t quite get the commented 6.x version to work).
But I haven´t found anything related to theme a cck list according to it´s results.
In example:
I´ve got this cck field (text - select list): favourite_color
inside the cck content type: info_about_me
In that field, the allowed values are:
red
blue
yellow
green
purple
pink
I want to show those words in their respective color when the user choose one.
Not in the editing form, but in the actual node view.
Is that possible?
Could be much easier if it would be a taxonomy instead of a cck select field?
Thanks for your help!!
Rosamunda
Comments
The following assumes the
The following assumes the fields names are info_about_me (text field/text area) and favourite_color (text - select list).
It further assumes the values in the select list are valid css colors.
If your text field has a different name you will need to modify step 2 to reflect your field name.
If your select field has a different name you will need to modify the file contents below, changing
style="color: <?php print $node->field_favourite_color[0]['safe']; ?>so field_favourite_color reflects your field names.What to do
Warning: The sample does not check the value of field_favourite_color to see if is set.
Contents for content-field-field_info_about_me.tpl.php (modified copy of content-field.tpl.php)
Thanks, Steve!
Thanks for your reply Steve!!!
I´ve looked for a template like that! thanks!!
As I need to show the field´s color according to the selected item inside the cck test list, I´m a bit confused with
style="color: <?php print $node->field_favourite_color[0]['value']; ?>Is there a way to add here something like
if the field say "red" print the <div class="red_answer">field</div>.Thanks again for your help!!
Rosamunda
Just replace
Just replace
with
and the value the user picked will become a class.
WARNING: This next suggestion will impact editing of existing content of this type since it changes the the key values.
If you want a different class name than what the string show to the user change the CCK value select value list so it had key value pairs something like this
In this case if the user selects 'red' the class will become 'red_answer'.
Thanks again Steve!!
Brilliant!
Clear, effective, nice and cute explanation. Thanks!
It works like magic :)
Rosamunda
Hi, I'd like to ask for some
Hi,
I'd like to ask for some tips on this:
For instance I have these allowed values (let's follow your example)
red_answer|red
blue_answer|blue
yellow_answer|yellow
green_answer|green
purple_answer|purple
pink_answer|pink
then, I want to show 'red' instead of 'red_answer'
using
<?php print $node->$field_fieldname[0]['value'];?>would give me red_answer. Any tips?
Off the top of my head I
Off the top of my head I think you want
<?php print $node->$field_fieldname[0]['view'];?>.when multiple options are
when multiple options are selected you should change the [0] with $delta to be sure that it spits out the correct class for each of the options.
Hope this helps you as well.
Authentically,
BassPlaya
What if we want to do this
What if we want to do this for the actual EDITING form?
I would like it so that when the user clicks on the pull down menu with the various colors, the actual color is shown in the pulldown.
Looking the same thing
Looking the same thing
UPDATE
If anyone looking for this here is the solution.
color.html :
colorcard.js :
and add images black.jpg, blue.jpg, white.jpg .... in folder images