Display image if field is not empty

More
10 years 4 months ago #41624 by nikotome
Good morning!

I'm new to FlexiContent and I'm finding it's an absolute great component.

I'm developing a template, and I would like to now if there is a way to find out if a field is empty. something like:
Code:
If (($this->fields['web']->display;) == NULL { whatever }

Can anyone help me on this? Thanks in advance

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

More
10 years 4 months ago #41626 by ggppdk
Hello

In short use:

// Item view (item layout)
$fvals = $item->fieldvalues[$field_id];

// in category view you may need to use $items[$i]->
$fvals = $items[$i]->fieldvalues[$field_id];


if ( !empty($fvals) ) ...


NOTE: our image/ image gallery field has a parameter for default image


In more details
the variable
...->display

exists only if you try to create the display HTML of the field, in your case it would be better to check the war field value which:
- is always available for checking
- is a lot faster that created field's HTML via ... putting in a template position or via ... getFieldDisplay()

Using the raw value of a field inside a template file

Regards


-- 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
10 years 4 months ago #41627 by nikotome
Thank you! I will give it a try

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

More
10 years 4 months ago #41648 by nikotome
Hi,

I have added a new field named facebook, and made sure it was added to the template too. The new id for this field is 32.

Then, I have written the following code in the template file:
Code:
$field_id = 32; $fvals = $item->fieldvalues[$field_id]; if ( !empty($fvals) ) { echo '<a href="' . $this->fields['facebook']->display . '<img src="/images/facebook_icon.png" />';

What's wrong?

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

More
10 years 4 months ago #41649 by wiebe

nikotome wrote: Hi,

I have added a new field named facebook, and made sure it was added to the template too. The new id for this field is 32.

Then, I have written the following code in the template file:

Code:
$field_id = 32; $fvals = $item->fieldvalues[$field_id]; if ( !empty($fvals) ) { echo '<a href="' . $this->fields['facebook']->display . '<img src="/images/facebook_icon.png" />';

What's wrong?


I should think it should be:
$item->fields->display

cheers
Wiebe

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

More
10 years 4 months ago #41650 by nikotome
Ops! Yes, thank you. But it's still not working...

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

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