Display a field depending the value of another. Is it possible?

More
4 years 7 months ago #78488 by grabit
Hello,

I am working on a new version of a website.

I need to display some fields with values only if another field is checked.

I have 3 text fields with a link created with pretext and posttext and I have the 4th field called availability a "checkbox image" used in the category but in the item view I need to use this field in order to trigger the display of the 3 first.

Is it possible and how do you manage to do it?

Thanks (from home) for your help.

An Apple a days keeps the doctor away

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

More
4 years 7 months ago #78489 by ggppdk
Hello

this not an uncommon question

here is how to do it in english FAQ

Using the raw value of a field inside a template file or inside the viewing layout of another field

maybe there is a French translation too in the French FAQ


-- 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...

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

More
4 years 7 months ago #78491 by grabit
So as I need 2 visualizations of that field the good idea is to create a second field with a php automatic with a template calling the content (not necessarily raw) of the 3 others.

Am I right ?

An Apple a days keeps the doctor away

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

More
4 years 7 months ago #78492 by ggppdk
Hello

a newer and better way
if you want this kind of custom display to appear everywhere
e.g. appear like this in modules too

then i suggest that you
1. create a custom layout 'values_mycustomname1.php' for the field (e.g. a new layout for the text field)
2. use the if statements inside your custom layout 'values_mycustomname1.php'
3. in field configuration select to use your custom layout


-- 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...

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

More
4 years 7 months ago - 4 years 7 months ago #78493 by micker
or more simple ... if your field is single value

1 create a field1 and field 2
2 put field2 in the renderonly position of your item layout or your category layour (this will create it but will not display it automatically)
3 edit you file view item_html5.php for example
Code:
<?php if (strip_tags($item->fields["fieldname1"]->display) == 'yourvalue) { echo $item->fields["fieldname2"]->display; } ?>

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]
Last edit: 4 years 7 months ago by ggppdk.

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

More
4 years 7 months ago - 4 years 7 months ago #78499 by grabit
OK.

I made a checkbox field with 4 values and asked to display values.

Then I created a new the template based on the value_default called value_availability

Then I modified the case b part of the template but it doesn't display anything I certainly made a mistake in the code.
Code:
// CASE b. Display only selected elements else { foreach ($value as $v) { // Skip empty/invalid values but add empty display, if in field group $element = !strlen($v) ? false : @$elements[ $v ]; if ( !$element || (isset($element->state) && $element->state < 1) ) // 0: unpublished, 1: published, 2: archived { if ( $is_ingroup ) $html[] = ''; continue; } if ($text_or_value == 0) $disp = $element->value; else if ($text_or_value == 1) $disp = $element->text; /* only for (*IMAGE) fields */ else if ($text_or_value == 2) $disp = !$image_type ? '<img src="'.$imgpath . $element->image .'" class="fc_ifield_val_img '.$tooltip_class.'" title="'.flexicontent_html::getToolTip(null, $element->text, 0).'" alt="'.$element->text.'" />' : '<span class="'. $_class .' '. $element->image .'" style="'.($icon_color ? 'color: '.$icon_color.';' : '').'" title="'.flexicontent_html::getToolTip(null, $element->text, 0).'"></span>' ; else $disp = ' <div class="fc_ifield_val_box"> '.(!$image_type ? '<img src="'. $imgpath . $element->image .'" class="fc_ifield_val_img '.($text_or_value == 4 ? $tooltip_class : '').'" '.($text_or_value == 4 ? 'title="'.flexicontent_html::getToolTip(null, $element->text, 0).'"' : '').' alt="'.$element->text.'" />' : '<span class="'. $_class .' '. $element->image .'" style="'.($icon_color ? 'color: '.$icon_color.';' : '').'" '.($text_or_value == 4 ? ' title="'.flexicontent_html::getToolTip(null, $element->text, 0).'"' : '').'"></span>' ).' <span class="alert alert-info fc_ifield_val_txt">'.($text_or_value == 3 ? $element->text : $element->value).'</span> </div> '; if ($disp == 0) $disp = $item->fields[schedules_cinenews]->display; else if ($disp == 1) $disp = $item->fields[vod-button]->display; else if ($disp == 2) $disp = $item->fields[bluray-button]->display; $html[] = $pretext . $disp . $posttext; $index[] = $pretext . $element->value . $posttext; } } // If field is multi-value with each value being an array of values, then implode current value into a single display string

Thanks for your help.

An Apple a days keeps the doctor away
Last edit: 4 years 7 months ago by grabit.

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

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.550 seconds
Save
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