Custom field in description if

  • Posts: 278
  • Thank you received: 14
  • Hikashop Business
4 years 10 months ago #307108

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

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

  • Posts: 81484
  • Thank you received: 13062
  • MODERATOR
4 years 10 months ago #307112

Hi,

You can do like that:

if(!empty($this->element->autortext)) {
  // your code
}

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

  • Posts: 278
  • Thank you received: 14
  • Hikashop Business
4 years 10 months ago #307209

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.

  • Posts: 12953
  • Thank you received: 1778
4 years 10 months ago #307220

Hello,

You should try it like this :

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

  • Posts: 278
  • Thank you received: 14
  • Hikashop Business
4 years 10 months ago #307346

Sorry for bother.

Now I get in html output

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

  • Posts: 1119
  • Thank you received: 114
4 years 10 months ago #307355

Hi,

Try like this:

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

  • Posts: 81484
  • Thank you received: 13062
  • MODERATOR
4 years 10 months ago #307347

Like that then:

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

  • Posts: 278
  • Thank you received: 14
  • Hikashop Business
4 years 10 months ago #307522

Nicolas, that is working great. Thank you.

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

Time to create page: 0.074 seconds
Powered by Kunena Forum