Custom field in description if

  • Posts: 48
  • Thank you received: 2
  • Hikashop Business
3 months 2 weeks 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: 66841
  • Thank you received: 9874
  • MODERATOR
3 months 2 weeks 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: 48
  • Thank you received: 2
  • Hikashop Business
3 months 2 weeks 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: 12131
  • Thank you received: 1672
  • MODERATOR
3 months 2 weeks 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: 48
  • Thank you received: 2
  • Hikashop Business
3 months 1 week 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: 1046
  • Thank you received: 100
  • Hikashop Business
3 months 1 week 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: 66841
  • Thank you received: 9874
  • MODERATOR
3 months 1 week 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: 48
  • Thank you received: 2
  • Hikashop Business
3 months 6 days 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.076 seconds
Powered by Kunena Forum