How to set php condition with field value ?

More
8 years 11 months ago - 8 years 11 months ago #54643 by bendeb
Hello, :)

I create a "radio button" field, named for the example "Display div ?" with theses field values parameters : 1::Yes%% 0::No%%
Then, in my template, I want to display a div (or whatever) if the value of the field above is set on Yes, and hide the same div if the value is set on No.

For now, I have this code in the item.php of my template :
Code:
<?php if ($this->fields['mydiv']->display = '1') { ?> <div> bla bla bla </div> <?php } else {} ?>

But it don't work. :(
I know the thing to change is : <?php if ($this->fields->display = '1') {
But I don't know the proper syntax.

Could you help me please ?

Thank in advance. :)

Flexicontent 4.1.0b1
Joomla 3.9.18
Last edit: 8 years 11 months ago by bendeb.

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

More
8 years 11 months ago #54646 by ggppdk
Hello,

you can read this FAQ article:
Using the raw value of a field inside a template file or inside a new custom field type

php code that you would use for field of type -radio- :
Code:
$field_id = 19; $theValues = $item->fieldvalues[$field_id]; // or $items[$i] for category view if ( !empty($theValues) && $theValues[0]=='1' ) { ?> <div>bbbb</div> <?php }

-- Note if you output is always the same then instead of custom code, you can do this:

1. Use a checkbox field instead with only 1 option
&nbsp;::Show Message%%

2. Put as prefix of every value: the HTML that you want to print
e.g.
<div>My notes</div>

This way the output of the field wil be:
Code:
<div>My notes</div>&nbsp;


-- 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
8 years 11 months ago - 8 years 11 months ago #54655 by bendeb
Thank ggppdk for your answer. :)
I tried your first method but it doesn't work for me. I don't know why.
I obviously replace field_19 by my field name but no success.

I tried your second method with prefix value and it's working but not very convenient for me.

But isn't there a method in the item.php file to catch a field value and set it in a php condition otherwise than the first method that you wrote above ?

This syntax, for example, works great :
Code:
<?php if ($this->fields['myfield']->display = NULL) { ?>

I want to replace NULL by 0 or 1 (the field value) or whatever else but I don't find the syntax nor I don't know if it could work.
I tried this, without success :
Code:
<?php if ($this->fields['myfield']->display = 1) { ?>
Code:
<?php if ($this->fields['myfield']->display = '1') { ?>
Code:
<?php if ($this->fields['myfield']->display == 1) { ?>
Code:
<?php if ($this->fields['myfield']->display == '1') { ?>
etc.

Thank in advance.

Flexicontent 4.1.0b1
Joomla 3.9.18
Last edit: 8 years 11 months ago by bendeb.

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

More
8 years 11 months ago #54656 by ggppdk
Hello

You need the field ID and the field name:

Try (replace 19 with your field ID):
Code:
$field_id = 19; $theValues = $item->fieldvalues[$field_id]; print_r($theValues);


-- 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
8 years 11 months ago #54661 by bendeb
Sorry, but it doesn't work for me.
I put this in the template :
Code:
<?php $field_id = 265; $theValues = $item->fieldvalues[$field_id]; print_r($theValues); ?>
Where 265 is my field ID.
But no value is displaying on the item view. :unsure:

Flexicontent 4.1.0b1
Joomla 3.9.18

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

More
8 years 11 months ago #54663 by ggppdk
Hello

265 ?

just asking
you have created (and delete some) 250 different fields ??


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

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.270 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