0

Anyone had this? I have a custom content type and I want to give an option to attach an image from a list of predefined images (in my case - a list of product series logotypes). The admin interface would be a simple dropdown of logotype labels:

- None -
Series 1
Series 2
Series 3

How would I then process the selection and convert it into a real image? What would be the best practice here?

Regards, Artur

2 Answers 2

1

These are general guidelines as I made something like this but for D6. I would create a logotype variable in template_preprocess_node and then loop on you dropdown variable. For each value selected I would add an <img src='path/to/logo1.png' alt='Logo 1' /> to your logotypes variables.
Then just display the variable in you node template.

0

Here you go:

<?php
    $logotypes = array(
        'dropdown_key1' => '[path_to_image_1]',
        'dropdown_key2' => '[path_to_image_2]'
    );    

   print('<ul>');
   foreach ($element['#object']->field_logotypy['pl'] as $logo){
        print "<li>" . $logotypes[$logo["value"]] . "</li>";
   }
     print('</ul>');
?>

This is placed in field--field_name--content-type.tpl.php. In the admin form, the editor selects a logotype name from a dropdown, which has predefined keys as in the $logotypes array. The values on the admin side will be the paths to actual logotype images.

What I don't like about the code is the hard-coded 'pl' language index used here. I assume though, that with some more reading I will be able to figure out how to address it better - the logotypes are actually not language-dependent.

HTH

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.