10 years ago
Topic

Hi,

I created a checkbox field with the following text and values :

  • TEXT1=image1.jpg
  • TEXT2=image2.jpg
  • TEXT3=image3.jpg

I use an HTML typo to display the image linked to the choice in the field : <img alt="my_alt" src="/image_path/*value*">

This works well and display image1.jpg when I check "TEXT1".

But I encounter an issue if I check more than one choice : The final HTML result append all file names in a single "img src" !

Here is the result in the page source : ... src="/image_path/image1.jpg,image2.jpg"

How to get one image per value ?

Thanks for your help,

Get a Book for SEBLOD
4229 Posts
Kadministrator
10 years ago
1
Level 1

Hi,

this is a bit complicated to do, you need to make a markup override (with seb_one rename _markup.php found ifn fields dir to markup.php) and then do an if inthere to render this field yourself

if ($field->name == 'yourfildname' ){

// do your output here

}

In this if you need to do explode on the $field->value t get an array of values and then do a foreach loop to replace values with links to images.

10 years ago
0
Level 2

Hi Klas, 

Thank you for your answer. Yes, maybe a bit complicated for a simple need.

Maybe I'm wrong in my use of the checkbox.

In fact, I want to use checkbox to manage keywords/tags for my articles. I want to link those keywords to a search list for each keyword. Same issue than linking checkbox images, It create a link for the whole set of keyword.

So, I think I'm not using the good way for that purpose. Can you give me an advice on how to associate mulitple keywords on articles, with the possibility of a link on each keyword performing a search for all articles with that keyword.

What is the good way to do that ?

Many thanks for your support,

Lionel

64 Posts
Topy
7 years ago
4
Level 1

Everyone who will search for this solution... you can use this code, only change the fieldname:

getValue('dotari_camere'); $images = explode( ',', $valuestring ); foreach ( $images as $image ) { $value .= ''; } echo "$value"; ?>

1283 Posts
Bucklash
7 years ago
3
Level 2

Hi

I think hat would make a cool tutorial.  

64 Posts
Topy
7 years ago
2
Level 3

Yep... i tried to display as title of image the option name... but i faild. I will search more for this solution..

1283 Posts
Bucklash
7 years ago
1
Level 4

If you var_dump $fields or $config you can see how to access it.. Have you done that? 

64 Posts
Topy
7 years ago
0
Level 5

I did it . Now this code will show your checkboxes as image with Title from your option.

<?php $valueString = $cck->getValue('dotari_camere'); $valueText = $cck->getText('dotari_camere'); if(!empty($valueString)){ $images = explode( ',', $valueString ); $vText = explode( ',', $valueText ); foreach ( $images as $i => $image ) { $value .= '<img src="/templates/sj_directory/images/travel/'.$image.'" title="'.$vText[$i].'" data-placement="top" data-original-title="Click here example Tooltip" style="width:35px; padding:0 5px;" />'; } echo "$value"; } else { echo "";}; ?>

Get a VIP membership