html - Prestashop 为特定类别创建自定义布局

标签 html css smarty prestashop prestashop-1.6

我正在尝试为客户的某些类别创建不同的布局。我找到了一些解决方案,例如 here但这是一个旧答案,我还需要更多细节。

我正在使用 Prestashop 1.6.0.9,我想创建一个 custom-product-list.tpl 文件来更改布局并添加一些小功能(获取产品描述、获取所有产品图片等)。

有没有人解决过这个问题?我不介意结构良好的漂亮代码,因为价格很低。如果硬编码既简单又快速,我会更喜欢它。

提前谢谢你。

最佳答案

可以有很多解决方案,但最常用的是这些。

1。编辑主题文件(首选)

Prestashop 类别模板位于文件 themes/[yourtheme]/category.tpl 中。

您可以像这样放置一些代码来编辑它:

YOUR_ID - 整数,类别的 ID。

{if isset($category) && isset($category->id) && $category->id == YOUR_ID}

    {* your custome code *}

{else}

    {* place all default category.tpl code here *}

{/if}

类别模板还包括 themes/[yourtheme]/product-list.tpl 以及您可以在代码中找到的其他文件。您可以相应地更改这些 .tpl 文件。

2。覆盖类别 Controller 。

您可以覆盖类别 Controller 并使其使用任何其他模板文件,而不仅仅是 themes/[yourtheme]/category.tpl

2.1 创建文件override/controllers/front/CategoryController.php,代码如下:

<?php

class CategoryController extends CategoryControllerCore
{
    public function initContent()
    {
        /* loading the default code */
        parent::initContent();

        /* please add all categories ID for which you want to use this custom template */
        $custom_categories = array(1, 3);

        if (isset($this->category) && in_array($this->category->id, $custom_categories))
        {
            /* please change the file name 'category-1.tpl' 
            to any other file name you want to use in your theme directory,
            i. e. themes/[yourtheme]/category-1.tpl */
            $this->setTemplate(_PS_THEME_DIR_.'category-1.tpl');
        }
    }
{
}

2.2 使用您的自定义代码创建文件 themes/[yourtheme]/category-1.tpl(或使用其他名称)。

2.3 可选。出于安全原因,将 index.php 文件从任何文件夹除了根文件夹复制到您在制作 2.1 部分时创建的文件夹(如果已创建)。

关于html - Prestashop 为特定类别创建自定义布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34790656/

相关文章:

javascript - 带有 rgba 的 Canvas 径向渐变在 Safari 和 IE 上不起作用

php - 在 Smarty tpl FIle 中使用 PHP 代码

smarty - smarty中如何显示有限的字符?

php - 什么时候你才能称自己为 PHP 专业人士?

java - 自动生成用于数据库 CRUD 操作的 html 表单

html - 如何在html中写方程式?

javascript - jquery更新后div内容被清除

javascript - 从某个点开始 scrolldiv

html - 设置父项高度相对于子项高度。

Jquery - 如何将 mouseleave 事件设置为 after() 生成的 div?