conditional css classes in fc template

More
14 years 5 months ago #466 by nico65
Hi,
first of all thanks a lot for this great Component! (The best CCK I see so far)

I just play around with your template system (very easy to understand even for a non php expert like me) but how can I ask if a Field is empty or not?

I try to explain:
I have two fields in the item description template
MainImageLeft and text
Now I want to append a css class if the MainImageLeft field is empty (just to adjust the width of the text field)

I tried it like this:
Code:
<!-- BOF description --> <div class="description"> <?php foreach ($this->item->positions['description'] as $field) : ?> <?php if ($field->label) : ?> <div class="desc-title"><?php echo $field->label; ?></div> <?php endif; ?> <div class="desc-content <?php echo $field->name; ?><?php if (!empty($item->name['MainImageLeft'])) : echo 'width50'; endif; ?>"><?php echo $field->display; ?></div> <?php endforeach; ?> </div> <!-- EOF description -->

or with
Code:
if ($this->params->get('MainImageLeft') != '') : echo 'width50'; endif;

But I guess guessing takes me no further. So I would be thankfull for any tip.

Nico

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

More
14 years 5 months ago #485 by vistamedia
Hi,
You can know it quite easily doing this :
Code:
if ($this->fields['MainImageLeft']->display) { do this.... }
In fact $this->item->positions is just a shortcut easier to manage for designers. It avoids them doing complex loops on the field object.
If you wish to know the complete field object structure put this in your template. This will help you a lot understanding what's inside.
Code:
<?php echo '<pre>'; print_r($this->fields['MainImageLeft']); echo '</pre>'; ?>
Cheers,
Emmanuel.

FLEXIcontent lead developer.
www.vistamedia.fr web agency and custom development.
www.joomla.fr co-administrator.
Please no PM for support request, use the forum for that!!!

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

More
14 years 5 months ago #493 by nico65
Hi,
thanks a lot that works fine.
although just in the item template not in the category_item template.

But I will be patient and wait for the update of the template tutorial.

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

More
14 years 5 months ago #497 by vistamedia
Hi,
It's exactly the same principle except the field object is associated to each item.
The code would be in this case for blog view
Code:
if ($this->items[$i]->fields['MainImageLeft']->display) { do this.... }
and for the table view
Code:
if ($this->item->fields['MainImageLeft']->display) { do this.... }

Cheers,
Emmanuel.

FLEXIcontent lead developer.
www.vistamedia.fr web agency and custom development.
www.joomla.fr co-administrator.
Please no PM for support request, use the forum for that!!!

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

More
14 years 5 months ago #499 by nico65
great, thanks again!

(Now when I see this, it looks quite logical, but when i tried to figure it out by myself I only got errors.
...I have to lern more php :) )

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

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