我想创建一个全局变量,该变量将被设置并进入.tpl文件。应当为用户保存全局变量(是否登录)

最佳答案

Override -> classes -> controller -> FrontController.php中创建替代

并添加代码:

<?php

use PrestaShop\PrestaShop\Adapter\Cart\CartPresenter;
use PrestaShop\PrestaShop\Adapter\ObjectPresenter;
use PrestaShop\PrestaShop\Adapter\Configuration as ConfigurationAdapter;
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Debug\Debug;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;

class FrontController extends FrontControllerCore
{
    public function initContent()
    {
        $this->context->smarty->assign(array(
            'VARIABLE_NAME' => VARIABLE_VALUE,
        ));
        return parent::initContent();
    }
}
?>

关于php - 如何在PrestaShop中的.tpl文件中创建全局变量?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57143786/

10-14 13:13