Background color in function of the field's value

More
8 years 10 hours ago - 8 years 1 hour ago #72259 by erica
hello,
I want to change a background-color of a field (in frontend view) function of the value of the field.
eg : if value == 1 background : green else background : red;
How i can make this ?
I searched in forum but without result
Last edit: 8 years 1 hour ago by ggppdk.

Please Log in or Create an account to join the conversation.

More
8 years 10 hours ago #72260 by ggppdk
Hello

it is easy you can
- duplicate the default layout file of the field, modify it
- then select it in field configuration

e.g. for "text" field
duplicate
Code:
plugins\flexicontent_fields\text\tmpl\value_default.php
as
Code:
plugins\flexicontent_fields\text\tmpl\value_mycoloredlayout.php


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star review. Thanks!

Please Log in or Create an account to join the conversation.

More
8 years 8 hours ago #72261 by micker
or just working in template view (need to adapte on categorie view or item view)
Code:
<?php $backclass=""; if($item->field['tonchamps'] == 1{ $backclass="Toncodecouleurrouge"; } else { $backclass="Toncodecouleurvert"; } ?> <div class="<?php echo $backclass; ?>" ....

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

More
8 years 7 hours ago #72262 by erica
Micker,

I prefere work with template view.
Where I write this code : file "item.php" (for the item view) ?

Please Log in or Create an account to join the conversation.

More
8 years 6 hours ago #72263 by ggppdk
Hello

if you do it with the custom field layout
then it will work everywhere

item view
category view
modules


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star review. Thanks!

Please Log in or Create an account to join the conversation.

More
8 years 6 hours ago #72264 by erica
Ok I anderstand.
I don't arrived to writte the good code in order to customise the background.
Could you explain more ?

Please Log in or Create an account to join the conversation.

More
8 years 6 hours ago - 8 years 6 hours ago #72265 by ggppdk
Hello

First create the new layout file value_mycoloredlayout.php to the folder i mentioned above

Then find code
Code:
// Add prefix / suffix $field->{$prop}[$n] = $pretext . $value . $posttext;

Replace it with
Code:
// Value to color (array) map $value_to_color = array( '0' => 'darkorange', '1' => 'brown', '2' => 'darkgreen', '3' => 'darkcyan' ); $colored_value = isset($value_to_color[$value]) ? '<span class="badge" style="background-color: ' . $value_to_color[$value] . '">' . $value . '</span>' : '<span class="badge" style="background-color: gray;">' . $value . '</span>'; // Add prefix / suffix $field->{$prop}[$n] = $pretext . $colored_value . $posttext;

I have not tested the above code, i just took 5 minutes to write it


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star review. Thanks!
Last edit: 8 years 6 hours ago by ggppdk.

Please Log in or Create an account to join the conversation.

More
8 years 5 hours ago #72268 by erica
It's for a text field, but in my case it's a radio field. I anderstand the principe of fonctionnement but for the radio field the code php is more complexe
What I must replace ?

Please Log in or Create an account to join the conversation.

More
8 years 4 hours ago - 8 years 3 hours ago #72271 by ggppdk
Hello
try this:

Find (note: Do not enable 'Show non-selected values' in field configuration):
Code:
$html[] = $pretext . $disp . $posttext;

Replace with
Code:
// Value to color (array) map $value_to_color = array( '0' => 'darkorange', '1' => 'brown', '2' => 'darkgreen', '3' => 'darkcyan' ); $colored_disp = isset($value_to_color[$element->value]) ? '<span class="badge" style="background-color: ' . $value_to_color[$element->value] . '">' . $disp . '</span>' : '<span class="badge" style="background-color: gray;">' . $disp . '</span>'; $html[] = $pretext . $colored_disp . $posttext;


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star review. Thanks!
Last edit: 8 years 3 hours ago by ggppdk.

Please Log in or Create an account to join the conversation.

More
8 years 3 hours ago - 8 years 1 hour ago #72277 by erica
You are the best.
It's working.
Thanks a lot.
Last edit: 8 years 1 hour ago by ggppdk.

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline
Save