Такая вот проблемка есть шаблон опенкарт 2.3 там код
<div class="col-2 offset-1">
<ul>
<?php foreach (array_slice($categories, 0, $half) as $category): ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
<?php endforeach ?>
</ul>
</div>
<div class="col-2 offset-1">
<ul>
<?php foreach (array_slice($categories, $half) as $category): ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
<?php endforeach ?>
</ul>
</div>
Конвертор его конвертирует вот так
<div class="col-2 offset-1">
<ul>
{% for category in rray_slice %}
<li><a href="{{ category.href }}">{{ category.name }}</a></li>
{% endfor %}
</ul>
</div>
<div class="col-2 offset-1">
<ul>
{% for category in rray_slice %}
<li><a href="{{ category.href }}">{{ category.name }}</a></li>
{% endfor %}
</ul>
</div>
Но так не работает!
Подскажите как правильно написать этот код для twig???
Вот код контролера
// Menu
$this->load->model('catalog/category');
$data['categories'] = array();
foreach ($this->model_catalog_category->getCategories(0) as $category) {
if ($category['top']) {
$data['categories'][] = array(
'name' => $category['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
$count = count($data['categories']) + 1;
$data['half'] = $count/ 2;
foreach ($categories as $category) {
if ($category['settings']) {
$settings = unserialize($category['settings']);
if ($settings['show_in_top'] == 0) continue;
}
$articles = array();
if ($category['settings'] && $settings['show_in_top_articles']) {
$filter = array('filter_category_id' => $category['category_id'],'filter_sub_category' => true);
$results = $this->model_newsblog_article->getArticles($filter);
foreach ($results as $result) {
$articles[] = array(
'name' => $result['name'],
'href' => $this->url->link('newsblog/article', 'newsblog_path=' . $category['category_id'] . '&newsblog_article_id=' . $result['article_id'])
);
}
}
$data['categories'][] = array(
'name' => $category['name'],
'children' => $articles,
'column' => 1,
'href' => $this->url->link('newsblog/category', 'newsblog_path=' . $category['category_id'])
);
}
<div class="col-2 offset-1">
<ul>
<?php foreach (array_slice($categories, 0, $half) as $category): ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
<?php endforeach ?>
</ul>
</div>
<div class="col-2 offset-1">
<ul>
<?php foreach (array_slice($categories, $half) as $category): ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
<?php endforeach ?>
</ul>
</div>
Конвертор его конвертирует вот так
<div class="col-2 offset-1">
<ul>
{% for category in rray_slice %}
<li><a href="{{ category.href }}">{{ category.name }}</a></li>
{% endfor %}
</ul>
</div>
<div class="col-2 offset-1">
<ul>
{% for category in rray_slice %}
<li><a href="{{ category.href }}">{{ category.name }}</a></li>
{% endfor %}
</ul>
</div>
Но так не работает!
Подскажите как правильно написать этот код для twig???
Вот код контролера
// Menu
$this->load->model('catalog/category');
$data['categories'] = array();
foreach ($this->model_catalog_category->getCategories(0) as $category) {
if ($category['top']) {
$data['categories'][] = array(
'name' => $category['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
$count = count($data['categories']) + 1;
$data['half'] = $count/ 2;
foreach ($categories as $category) {
if ($category['settings']) {
$settings = unserialize($category['settings']);
if ($settings['show_in_top'] == 0) continue;
}
$articles = array();
if ($category['settings'] && $settings['show_in_top_articles']) {
$filter = array('filter_category_id' => $category['category_id'],'filter_sub_category' => true);
$results = $this->model_newsblog_article->getArticles($filter);
foreach ($results as $result) {
$articles[] = array(
'name' => $result['name'],
'href' => $this->url->link('newsblog/article', 'newsblog_path=' . $category['category_id'] . '&newsblog_article_id=' . $result['article_id'])
);
}
}
$data['categories'][] = array(
'name' => $category['name'],
'children' => $articles,
'column' => 1,
'href' => $this->url->link('newsblog/category', 'newsblog_path=' . $category['category_id'])
);
}