Skip to main content

Custom field in description if

More
7 years 3 months ago #307108 by mojweb
-- HikaShop version -- : 4.0.3
-- Joomla version -- : 3.9.6
-- PHP version -- : 7.2

I have customized view product/show_default to show some custom fields like that
Code:
<div class="row-fluid"> <div class="col-sm-2 phot"><?php $fieldClass = hikashop_get('class.field'); $field = $fieldClass->getField('autorfoto', 'product'); echo $fieldClass->show($field,$this->element->autorfoto); ?> </div> <div class="col-sm-10 text"><?php echo $this->element->autortext; ?></div> </div>
I get right output, but row displays if fields are empty. What code to add (some php if) to show row div only when fields filled up.
thank you

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

More
7 years 3 months ago #307112 by nicolas
Hi,

You can do like that:
Code:
if(!empty($this->element->autortext)) { // your code }

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

More
7 years 3 months ago #307209 by mojweb
I get error. Something doing it wrong. Can you please add me code to my code.

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

More
7 years 3 months ago #307220 by Mohamed Thelji
Hello,

You should try it like this :
Code:
<div class="row-fluid"> <div class="col-sm-2 phot"><?php $fieldClass = hikashop_get('class.field'); $field = $fieldClass->getField('autorfoto', 'product'); echo $fieldClass->show($field,$this->element->autorfoto); ?> </div> <div class="col-sm-10 text"><?php if(!empty($this->element->autortext)) { echo $this->element->autortext; } ?> </div> </div>

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

More
7 years 3 months ago #307346 by mojweb
Sorry for bother.

Now I get in html output
Code:
<div class="row-fluid"> <div class="col-sm-2 avtorphot"><img class="" src="/poslovno/order/download/field_table-product/field_namekey-YXV0b3Jmb3Rv/name-/thumbnail_x-100/thumbnail_y-100" alt=""> </div> <div class="col-sm-10 avtortekst"></div> </div>

Image is not selected, so it should be empty. And I need to hide divs to if empty field.

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

More
7 years 3 months ago #307355 by kyratn
Hi,

Try like this:
Code:
<div class="row-fluid"> <?php $fieldClass = hikashop_get('class.field'); $field = $fieldClass->getField('autorfoto', 'product'); if(!empty($fieldClass->show($field,$this->element->autorfoto))) {?> <div class="col-sm-2 phot"><?php echo $fieldClass->show($field,$this->element->autorfoto);?></div> <?php } if(!empty($this->element->autortext)) {?> <div class="col-sm-10 text"><?php echo $this->element->autortext;?></div> <?php }?> </div>

Thanks

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

More
7 years 3 months ago #307347 by nicolas
Like that then:
Code:
<div class="row-fluid"> <?php if(!empty($this->element->autorfoto)) { $fieldClass = hikashop_get('class.field'); $field = $fieldClass->getField('autorfoto', 'product'); echo '<div class="col-sm-2 phot">' . $fieldClass->show($field,$this->element->autorfoto) . '</div>'; } if(!empty($this->element->autortext)) { echo '<div class="col-sm-10 text">' . $this->element->autortext . '</div>'; } ?> </div>
The following user(s) said Thank You: mojweb

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

More
7 years 3 months ago #307522 by mojweb
Nicolas, that is working great. Thank you.

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

Time to create page: 0.267 seconds
Powered by Kunena Forum