how to add the image from a custom field into the product detail view

  • Posts: 304
  • Thank you received: 22
13 hours 57 minutes ago #368234

-- HikaShop version -- : 6.1.0
-- Joomla version -- : 5.3.3
-- PHP version -- : 8

Hi,
I'm trying to make an image visible on the product detail page that comes from a custom field (name is productheaderfoto) with the type product > image
Have uploaded a demo image but it's not showing up when I try to show it with this code:

      <?php if (!empty($this->element->productheaderfoto)) : ?>
<div class="productheaderfoto">
<img src="/images/com_hikashop/upload/safe/<?php echo htmlspecialchars($this->element->productheaderfoto, ENT_QUOTES, 'UTF-8'); ?>"
alt="<?php echo htmlspecialchars($this->element->product_name, ENT_QUOTES, 'UTF-8'); ?>" />
</div>
<?php endif; ?>

I'm no progammer so my borrowed code is probably not the way for this type of field?

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

  • Posts: 84233
  • Thank you received: 13675
  • MODERATOR
1 hour 51 minutes ago #368235

Hi,

What is the type of the field ?
If it's "text" and you enter the filename of the image in the text input field, then your code will work.
However, if it's "AJAX image", then it cannot work like that. You need to ask HikaShop's class.field to show the img tag for you:
www.hikashop.com/forum/product-category-...t-layout.html#339434
So, for example:

      <?php if (!empty($this->element->productheaderfoto)) : ?>
<div class="productheaderfoto">
<?php
$fieldClass = hikashop_get('class.field');
$field = $fieldClass->getField('productheaderfoto', 'product');
echo $fieldClass->show($field,$this->element->productheaderfoto);
?>
</div>
<?php endif; ?>

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

Time to create page: 0.039 seconds
Powered by Kunena Forum