Post by oliwin » Thu Oct 26, 2017 6:42 am

I added image tag in HTML editor (HTML content module). I tried to set custom path like:

Code: Select all

/image/icons/my.png
But it replaces this on default path like:

Code: Select all

sites-images/my.png
But there is not directory sites-images in project

New member

Posts

Joined
Tue Jan 10, 2017 2:00 am

Post by straightlight » Thu Oct 26, 2017 7:08 am

By viewing the view source interface of the default theme of Opencart on your browser, you can see the direct path of all images from every public page on your store. Another way would be by defining the image path from the relative controller that will output the template. An example would be like this, for instance:

Code: Select all

$this->load->model('tool/image');

$data['my_image'] = $this->model_tool_image->resize($product_info['my_image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_thumb_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_thumb_height'));
This will load an image from the database which the field: my_image would need to exist but for this demonstration, you won't need it obviously.

From an actual image without relying on the database but directly on your file server, you could use:

Code: Select all

$data['my_image'] = DIR_IMAGE . 'my_image.ext';
Both case, in your related TWIG file, you could then use:

Code: Select all

{% if my_image %}
<img src="{{ my_image }}">
{% endif %}
The easiest way would be following the view source for each relative path but not the most simplified solution for merchants who uses multiple themes since each theme may use their own image path. However, that is not an obligation.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Miftaul_Jannat » Thu Sep 01, 2022 5:14 pm

$data['my_image'] = DIR_IMAGE . 'my_image.ext';
here "my_image.ext" I use my image name "pcbuilder_logo.png" but it doesn't work. What should I do?


Posts

Joined
Thu Dec 09, 2021 11:58 pm

Post by straightlight » Thu Sep 01, 2022 6:14 pm

Miftaul_Jannat wrote:
Thu Sep 01, 2022 5:14 pm
$data['my_image'] = DIR_IMAGE . 'my_image.ext';
here "my_image.ext" I use my image name "pcbuilder_logo.png" but it doesn't work. What should I do?
OC version. You ain't doing it right.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 515 guests