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

  • Posts: 305
  • Thank you received: 22
1 day 4 hours 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: 13677
  • MODERATOR
16 hours 49 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; ?>

The following user(s) said Thank You: nico.van.leeuwen

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

  • Posts: 305
  • Thank you received: 22
14 hours 3 minutes ago #368236

Thank you, that works perfectly. Is was indeed the ajax version.

A small thing but it would be a nice addition if the images that you upload that way would have a max-width when you show the preview in the backend. Now it's going all over the place because this image is pretty big :-)

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

Time to create page: 0.101 seconds
Powered by Kunena Forum