PrestaShop 1.7.4 覆盖管理模板
PrestaShop 1.7.4 override admin template
我正在开发自己的模块。
如何覆盖位于以下位置的模板:
\admin\themes\default\template\controllers\customers\helpers\view\view.tpl ?
我在模块文件夹中创建了文件:
\modules\my_module_name\override\controllers\admin\templates\customers\helpers\view\view.tpl。
当我安装我的模块时,文件夹 \override\controllers\admin\templates\ 是空的。
根据 Prestashop DevDocs,我们不能通过将管理模板文件放在我们模块的 override
文件夹中来直接覆盖模板。
Overriding a theme from a module is NOT possible, and never will. If
you need this, you have to look instead at the parent/child theme
feature.
你可以做的一件事是你可以将 template
文件放在 override
文件夹中,然后将这些文件复制到模块 install/reset
上,然后删除模块 [=19= 上的这些文件].为了实现这一点,我们可以在 Prestashop 默认提供的 install()
和 uninstall()
函数中调用我们的 function
到 copy
覆盖和 remove
覆盖。
您需要在模块中执行下面提到的步骤来覆盖管理模板。
1) 添加需要在模块中覆盖的模板文件列表 __construct()
方法
__construct() 方法
public function __construct()
{
// ..... your other code here ....
// list of template(s) file that needs to be override
$this->admin_tpl_overrides = array(
implode(DIRECTORY_SEPARATOR, array('override', 'controllers', 'admin', 'templates', 'customers', 'helpers', 'view', 'view.tpl'))
);
}
2) 在以下路径的模块覆盖文件夹中添加要覆盖的 view.tpl
文件。确保已在此文件中完成更改。
modules\{YOUR_MODULE_NAME}\override\controllers\admin\templates\customers\helpers\view
3) 修改模块 class 文件中的 install()
和 uninstall()
方法。
安装方法
public function install()
{
$addAdminTplOverrides = $this->_addAdminTplOverrides();
return parent::install() && $addAdminTplOverrides /** Other hook you need to register + Method you need to call on install **/;
}
uninstall() 方法
public function uninstall()
{
$removeAdminTplOverrides = $this->_removeAdminTplOverrides();
return parent::uninstall() && $removeAdminTplOverrides /** Other hook you need to un-register + Method you need to call on uninstall **/;
}
4) 在install()
和uninstall()
中分别调用了_addAdminTplOverrides()
和_removeAdminTplOverrides()
方法;在卸载方法之后添加这些功能。
private function _addAdminTplOverrides()
{
$module_override_path = $this->getLocalPath().DIRECTORY_SEPARATOR;
$result = true;
foreach ($this->admin_tpl_overrides as $admin_tpl_path) {
$override_file_path = $module_override_path.$admin_tpl_path;
$dest_override_file_path = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$admin_tpl_path;
if(file_exists($override_file_path)) {
if (!copy($override_file_path, $dest_override_file_path)) {
$result &= false;
}
} else {
$result &= false;
}
}
return $result;
}
private function _removeAdminTplOverrides()
{
$module_override_path = $this->getLocalPath().DIRECTORY_SEPARATOR;
$result = true;
foreach ($this->admin_tpl_overrides as $admin_tpl_path) {
$dest_override_file_path = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$admin_tpl_path;
if(file_exists($dest_override_file_path)) {
if (!unlink($dest_override_file_path)) {
$result &= false;
}
}
}
return $result;
}
5) 现在 install/reset
您的模块;你可以看到管理模板现在被覆盖了。
在这里完成第 1 步到第 5 步的代码
public function __construct()
{
// ..... your other code here ....
// list of template(s) file that needs to be override
$this->admin_tpl_overrides = array(
implode(DIRECTORY_SEPARATOR, array('override', 'controllers', 'admin', 'templates', 'customers', 'helpers', 'view', 'view.tpl'))
);
}
public function install()
{
$addAdminTplOverrides = $this->_addAdminTplOverrides();
return parent::install() && $addAdminTplOverrides /** Other hook you need to register + Method you need to call on install **/;
}
public function uninstall()
{
$removeAdminTplOverrides = $this->_removeAdminTplOverrides();
return parent::uninstall() && $removeAdminTplOverrides /** Other hook you need to un-register + Method you need to call on uninstall **/;
}
private function _addAdminTplOverrides()
{
$module_override_path = $this->getLocalPath().DIRECTORY_SEPARATOR;
$result = true;
foreach ($this->admin_tpl_overrides as $admin_tpl_path) {
$override_file_path = $module_override_path.$admin_tpl_path;
$dest_override_file_path = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$admin_tpl_path;
if(file_exists($override_file_path)) {
if (!copy($override_file_path, $dest_override_file_path)) {
$result &= false;
}
} else {
$result &= false;
}
}
return $result;
}
private function _removeAdminTplOverrides()
{
$module_override_path = $this->getLocalPath().DIRECTORY_SEPARATOR;
$result = true;
foreach ($this->admin_tpl_overrides as $admin_tpl_path) {
$dest_override_file_path = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$admin_tpl_path;
if(file_exists($dest_override_file_path)) {
if (!unlink($dest_override_file_path)) {
$result &= false;
}
}
}
return $result;
}
希望这些对您有所帮助!
我正在开发自己的模块。
如何覆盖位于以下位置的模板: \admin\themes\default\template\controllers\customers\helpers\view\view.tpl ?
我在模块文件夹中创建了文件: \modules\my_module_name\override\controllers\admin\templates\customers\helpers\view\view.tpl。
当我安装我的模块时,文件夹 \override\controllers\admin\templates\ 是空的。
根据 Prestashop DevDocs,我们不能通过将管理模板文件放在我们模块的 override
文件夹中来直接覆盖模板。
Overriding a theme from a module is NOT possible, and never will. If you need this, you have to look instead at the parent/child theme feature.
你可以做的一件事是你可以将 template
文件放在 override
文件夹中,然后将这些文件复制到模块 install/reset
上,然后删除模块 [=19= 上的这些文件].为了实现这一点,我们可以在 Prestashop 默认提供的 install()
和 uninstall()
函数中调用我们的 function
到 copy
覆盖和 remove
覆盖。
您需要在模块中执行下面提到的步骤来覆盖管理模板。
1) 添加需要在模块中覆盖的模板文件列表 __construct()
方法
__construct() 方法
public function __construct()
{
// ..... your other code here ....
// list of template(s) file that needs to be override
$this->admin_tpl_overrides = array(
implode(DIRECTORY_SEPARATOR, array('override', 'controllers', 'admin', 'templates', 'customers', 'helpers', 'view', 'view.tpl'))
);
}
2) 在以下路径的模块覆盖文件夹中添加要覆盖的 view.tpl
文件。确保已在此文件中完成更改。
modules\{YOUR_MODULE_NAME}\override\controllers\admin\templates\customers\helpers\view
3) 修改模块 class 文件中的 install()
和 uninstall()
方法。
安装方法
public function install()
{
$addAdminTplOverrides = $this->_addAdminTplOverrides();
return parent::install() && $addAdminTplOverrides /** Other hook you need to register + Method you need to call on install **/;
}
uninstall() 方法
public function uninstall()
{
$removeAdminTplOverrides = $this->_removeAdminTplOverrides();
return parent::uninstall() && $removeAdminTplOverrides /** Other hook you need to un-register + Method you need to call on uninstall **/;
}
4) 在install()
和uninstall()
中分别调用了_addAdminTplOverrides()
和_removeAdminTplOverrides()
方法;在卸载方法之后添加这些功能。
private function _addAdminTplOverrides()
{
$module_override_path = $this->getLocalPath().DIRECTORY_SEPARATOR;
$result = true;
foreach ($this->admin_tpl_overrides as $admin_tpl_path) {
$override_file_path = $module_override_path.$admin_tpl_path;
$dest_override_file_path = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$admin_tpl_path;
if(file_exists($override_file_path)) {
if (!copy($override_file_path, $dest_override_file_path)) {
$result &= false;
}
} else {
$result &= false;
}
}
return $result;
}
private function _removeAdminTplOverrides()
{
$module_override_path = $this->getLocalPath().DIRECTORY_SEPARATOR;
$result = true;
foreach ($this->admin_tpl_overrides as $admin_tpl_path) {
$dest_override_file_path = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$admin_tpl_path;
if(file_exists($dest_override_file_path)) {
if (!unlink($dest_override_file_path)) {
$result &= false;
}
}
}
return $result;
}
5) 现在 install/reset
您的模块;你可以看到管理模板现在被覆盖了。
在这里完成第 1 步到第 5 步的代码
public function __construct()
{
// ..... your other code here ....
// list of template(s) file that needs to be override
$this->admin_tpl_overrides = array(
implode(DIRECTORY_SEPARATOR, array('override', 'controllers', 'admin', 'templates', 'customers', 'helpers', 'view', 'view.tpl'))
);
}
public function install()
{
$addAdminTplOverrides = $this->_addAdminTplOverrides();
return parent::install() && $addAdminTplOverrides /** Other hook you need to register + Method you need to call on install **/;
}
public function uninstall()
{
$removeAdminTplOverrides = $this->_removeAdminTplOverrides();
return parent::uninstall() && $removeAdminTplOverrides /** Other hook you need to un-register + Method you need to call on uninstall **/;
}
private function _addAdminTplOverrides()
{
$module_override_path = $this->getLocalPath().DIRECTORY_SEPARATOR;
$result = true;
foreach ($this->admin_tpl_overrides as $admin_tpl_path) {
$override_file_path = $module_override_path.$admin_tpl_path;
$dest_override_file_path = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$admin_tpl_path;
if(file_exists($override_file_path)) {
if (!copy($override_file_path, $dest_override_file_path)) {
$result &= false;
}
} else {
$result &= false;
}
}
return $result;
}
private function _removeAdminTplOverrides()
{
$module_override_path = $this->getLocalPath().DIRECTORY_SEPARATOR;
$result = true;
foreach ($this->admin_tpl_overrides as $admin_tpl_path) {
$dest_override_file_path = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$admin_tpl_path;
if(file_exists($dest_override_file_path)) {
if (!unlink($dest_override_file_path)) {
$result &= false;
}
}
}
return $result;
}
希望这些对您有所帮助!