blocktopmenu.tpl中的菜单模板在哪里

时间:2016-03-30 08:53:08

标签: prestashop prestashop-1.6

每个人,我都很厌倦在Prestashop中找到{$MENU}模板。我试图找到很多时间和研究,但我找不到它。我想从{$MENU}自定义模板。有人能帮助我吗?

这是我的blocktopmenu.tpl文件:

{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">&nbsp;</div>

<!--/ Menu -->
{/if}

1 个答案:

答案 0 :(得分:2)

正如您所知,Blocktopmenu是一个真正的定制痛苦。

菜单本身没有模板文件。您必须破解(或覆盖)模块才能自定义渲染。

例如,我必须向liul元素添加一些类和ID。

以下是文件generateCategoriesMenu()内的默认/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;
}

这是我在/override/modules/blocktopmenu/blocktopmenu.php内的Hack:

<?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;
    }
}

正如您所看到的,在没有调用模板文件的情况下,在此classe中生成了html代码。