X
X
xXRustamXx2018-02-04 15:38:16
CMS
xXRustamXx, 2018-02-04 15:38:16

Can't display banner photo by id?

I use 3 opencart, I want to display all its images by banner id, but something doesn’t work, please tell me what I’m doing wrong ..........

<ul class="our_brands_items">
  {% for banner in banners %}
     {% if banner.banner_name == 10 %}
         <li class="col-md-3"><img src="{{ banner.image }}" alt="ALT"></li>
       {% endif %}
   {% endfor %} 
</ul>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zoozag, 2018-02-04
@xXRustamXx

You have not prepared the data in the controller to display it in the view.
An example of a controller for displaying banners catalog/controller/extension/module/banner.php
Approximately this code needs to be added to the main page controller:

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

$data['banners'] = array();

$results = $this->model_design_banner->getBanner(7);

foreach ($results as $result) {
  if (is_file(DIR_IMAGE . $result['image'])) {
    $data['banners'][] = array(
      'title' => $result['title'],
      'link'  => $result['link'],
      'image' => $this->model_tool_image->resize($result['image'], 200, 200)
    );
  }
}

The code in the template is:
<ul class="our_brands_items row">
  {% for banner in banners %}
         <li class="col-md-3"><img src="{{ banner.image }}" alt="ALT"></li>
   {% endfor %} 
</ul>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question