Reputation: 147
Everyone, I am very tired to find {$MENU}
template in Prestashop. I tried to find many time and research too but I can't find it. I want to customize template from {$MENU}
. Can someone help me?
This is my blocktopmenu.tpl
file:
{if $MENU != ''}
<!-- Menu -->
<div class="sf-contener clearfix">
<ul class="sf-menu clearfix">
{$MENU}
{if $MENU_SEARCH}
<li class="sf-search noBack" style="float:right">
<form id="searchbox" action="{$link->getPageLink('search')|escape:'html'}" method="get">
<p>
<input type="hidden" name="controller" value="search" />
<input type="hidden" value="position" name="orderby"/>
<input type="hidden" value="desc" name="orderway"/>
<input type="text" name="search_query" value="{if isset($smarty.get.search_query)}{$smarty.get.search_query|escape:'html':'UTF-8'}{/if}" />
</p>
</form>
</li>
{/if}
</ul>
</div>
<div class="sf-right"> </div>
<!--/ Menu -->
{/if}
Upvotes: 1
Views: 1955
Reputation: 5748
As you already know, Blocktopmenu is a real pain to customize.
There is no template file for the menu itself. You'll have to hack (or override) the module to customize the rendering.
For example I had to add some classes and ids to the li
and ul
elements.
Here is the default generateCategoriesMenu()
method inside file /modules/blocktopmenu/blocktomenu.php
:
protected function generateCategoriesMenu($categories, $is_children = 0)
{
$html = '';
foreach ($categories as $key => $category) {
if ($category['level_depth'] > 1) {
$cat = new Category($category['id_category']);
$link = Tools::HtmlEntitiesUTF8($cat->getLink());
} else {
$link = $this->context->link->getPageLink('index');
}
/* Whenever a category is not active we shouldnt display it to customer */
if ((bool)$category['active'] === false) {
continue;
}
$html .= '<li'.(($this->page_name == 'category'
&& (int)Tools::getValue('id_category') == (int)$category['id_category']) ? ' class="sfHoverForce"' : '').'>';
$html .= '<a href="'.$link.'" title="'.$category['name'].'">'.$category['name'].'</a>';
if (isset($category['children']) && !empty($category['children'])) {
$html .= '<ul>';
$html .= $this->generateCategoriesMenu($category['children'], 1);
if ((int)$category['level_depth'] > 1 && !$is_children) {
$files = scandir(_PS_CAT_IMG_DIR_);
if (count(preg_grep('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $files)) > 0) {
$html .= '<li class="category-thumbnail">';
foreach ($files as $file) {
if (preg_match('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $file) === 1) {
$html .= '<div><img src="'.$this->context->link->getMediaLink(_THEME_CAT_DIR_.$file)
.'" alt="'.Tools::SafeOutput($category['name']).'" title="'
.Tools::SafeOutput($category['name']).'" class="imgm" /></div>';
}
}
$html .= '</li>';
}
}
$html .= '</ul>';
}
$html .= '</li>';
}
return $html;
}
And here is my Hack inside /override/modules/blocktopmenu/blocktopmenu.php
:
<?php
if (!defined('_PS_VERSION_'))
exit;
class BlocktopmenuOverride extends Blocktopmenu
{
protected function generateCategoriesMenu($categories, $is_children = 0)
{
$html = '';
foreach ($categories as $key => $category) {
if ($category['level_depth'] > 1) {
$cat = new Category($category['id_category']);
$link = Tools::HtmlEntitiesUTF8($cat->getLink());
} else {
$link = $this->context->link->getPageLink('index');
}
if ((bool)$category['active'] === false) {
continue;
}
$html .= '<li id="menu-category-'.(int)$category['id_category'].'" class="'.(($this->page_name == 'category'
&& (int)Tools::getValue('id_category') == (int)$category['id_category']) ? 'sfHoverForce' : '').' menu-category-element-depth-' . (int)$category['level_depth'] . ' ' . ((isset($category['children']) && !empty($category['children'])) ? 'has-child' : '') . '">';
$html .= '<a href="'.$link.'" title="'.$category['name'].'"><span>'.$category['name'].'</span></a>';
if (isset($category['children']) && !empty($category['children'])) {
if ((int)$category['level_depth'] >= 3) {
$categoryLink = '<a href="'.$link.'">'.$category['name'].'</a>';
$html .= '<div class="sfCatLink">'.sprintf($this->l('Accéder aux articles %s'), $categoryLink).'</div>';
}
$html .= '<ul id="menu-category-' . (int)$category['id_category'] . '-childrens" class="menu-category-depth-' . (int)$category['level_depth'] . '">';
if ((int)$category['level_depth'] <= 4) {
$html .= $this->generateCategoriesMenu($category['children'], 1);
}
$html .= '</ul>';
}
$html .= '</li>';
}
return $html;
}
}
As you can see the html code is generated inside this classe without calling template files.
Upvotes: 3