Prestashop 自定义页面与自己的模板 [英] Prestashop custom page with own template
问题描述
我正在运行我自己的 prestashop 主题并想添加一个没有 css 的新页面.因此我添加了三个文件 php、控制器和模板.我将 php 放在我的 prestashop 的根目录中,将控制器添加到 root/controllers/front 并将模板放在 root/themes/my-theme 中.
如果我调用 http://localhost/prestashop/?page=custom-page,我查看索引起始页,如果我调用 localhost/prestashop/custom-page,我会得到一个 HTTP 404.
有人可以帮助我显示我的页面吗?
PHP:
display(_PS_THEME_DIR_.'custom-page.tpl');包括(目录名(__FILE__).'/footer.php');
控制器:
公共函数init(){父::init();}公共函数 initContent(){父::initContent();$this->setTemplate(_PS_THEME_DIR_.'custom-page.tpl');}//公共函数setMedia(){//parent::setMedia();//$this->addCSS(_THEME_CSS_DIR_.'custom-page.css');//$this->addJS(_THEME_JS_DIR_.'custom-page.js');//}
}
模板:
你好页面{文字}<style type="text/css"></风格>{/文字}<script type="text/javascript">{文字}{/文字}
对于 PS 1.7,请按照以下步骤创建一个新页面:
创建控制器:/controllers/front/MyPageController.php
setTemplate('mypage');}}
在您的主题中创建 tpl 文件:/themes/YOUR_THEME/templates/mypage.tpl
{extends file='page.tpl'}{块名称='page_header_container'}{/块}{块名称='page_content'}页面内容在这里{/堵塞}
删除类索引文件:/var/cache/dev/class_index.php
和/var/cache/prod/class_index.php
如何访问:http://your-site.com/index.php?controller=mypage
最后:
如果你想为这个页面处理一个友好的 URL,只需在 Shop Parameters > 中添加页面即可.交通SEO
.
I am running my own prestashop theme and want to add a new page without the css.
Therefore I added the three files php, controller and template. I placed the php in the root directory of my prestashop, added the controller to root/controllers/front and placed the template in root/themes/my-theme.
If I call http://localhost/prestashop/?page=custom-page, I see the index start page, If I call localhost/prestashop/custom-page, I get a HTTP 404.
Can someone help me to get my page displayed?
PHP:
<?php
include(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();
include(dirname(__FILE__).'/header.php');
$smarty->display(_PS_THEME_DIR_.'custom-page.tpl');
include(dirname(__FILE__).'/footer.php');
Controller:
public function init(){
parent::init();
}
public function initContent(){
parent::initContent();
$this->setTemplate(_PS_THEME_DIR_.'custom-page.tpl');
}
//public function setMedia(){
//parent::setMedia();
//$this->addCSS(_THEME_CSS_DIR_.'custom-page.css');
//$this->addJS(_THEME_JS_DIR_.'custom-page.js');
//}
}
Template:
<div>
HELLO PAGE
</div>
{literal}
<style type="text/css">
</style>
{/literal}
<script type="text/javascript">
{literal}
{/literal}
</script>
For PS 1.7, create a new page following the next steps:
Create the controller: /controllers/front/MyPageController.php
<?php
class MyPageControllerCore extends FrontController
{
public $php_self = 'mypage';
public $ssl = true;
public function initContent()
{
parent::initContent();
$this->setTemplate('mypage');
}
}
Create the tpl file in your theme: /themes/YOUR_THEME/templates/mypage.tpl
{extends file='page.tpl'}
{block name='page_header_container'}{/block}
{block name='page_content'}
PAGE CONTENT HERE
{/block}
Delete the class index files: /var/cache/dev/class_index.php
and /var/cache/prod/class_index.php
How to access it: http://your-site.com/index.php?controller=mypage
Finally:
If you want to handle a friendly URL for this page, just add the page in Shop Parameters > Traffic & SEO
.
这篇关于Prestashop 自定义页面与自己的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!