Chill_user Posted April 20, 2020 Share Posted April 20, 2020 Hello to all, I have a question about how to create custom page programmatically. I need to create a page, where I can place my content. I know that I can create controller, than go to the "Traffic and SEO" and add a custom controller. It's like semi-programmatical method. But my question is how to create the page with PHP Thanks a lot! P.S. I know it's not easy, but you can explain just logic. P.S2 I know that we have CMS class in /classes but it creates a page where you need to define a controller Link to comment Share on other sites More sharing options...
Guest Posted April 21, 2020 Share Posted April 21, 2020 Tutorial for Prestashop 1.7 1. create front controller <?php class custompageControllerCore extends FrontController { public $php_self = 'custompage'; public function initContent() { $this->context->smarty->assign( array( 'variable1' => 'Variable 1', 'variable2' => 'Variable 2', ) ); parent::initContent(); $this->setTemplate('custompage'); } } 2. save to ./controllers/front/custompageController.php 3. create tpl file {extends file='page.tpl'} {block name='page_title'} <span class="sitemap-title">{l s='Custom page' d='Shop.Theme'}</span> {/block} {block name='page_content'} <h2>My test page content</h2> <span>{$variable1}</span><br /> <span>{$variable2}</span><br /> {/block} 4. save to ./themes/your theme/templates/custompage.tpl 5. Admin -> Shop parameters -> Traffic & SEO 6. Click add new page 7. Select "Page name" custompage 8. Rewritten URL = my-custom-page 9. Save 10. Admin -> Advanced Parameters -> Performance 11. clear cache and recompile template 12. go to: https://your-store-url/my-custom-page 13. go to this post and like by clicking on the gray heart below the post 😉 Link to comment Share on other sites More sharing options...
Guest Posted April 21, 2020 Share Posted April 21, 2020 (edited) Follow these instructions to programmatically create PHP and tpl files. You also know where to store them. Instead of creating SEO you can insert values into the database (`ps_meta_lang`). $languages = Language::getLanguages(false, $this->context->shop->id); $get_meta_id = Db::getInstance()->getValue('SELECT id_meta FROM '._DB_PREFIX_.'meta_lang ORDER BY id_meta DESC;') + 1; foreach ($languages as $lang) { Db::getInstance()->Execute( "INSERT INTO `"._DB_PREFIX_."meta_lang` (`id_meta`, `id_shop`, `id_lang`, `title`, `description`, `keywords`, `url_rewrite`) VALUES (".$get_meta_id.", 1, ".$lang['id_lang'].", 'my custom page', 'created my custom page', 'my,custom,page', 'my-custom-page')" ); } Db::getInstance()->Execute("INSERT INTO "._DB_PREFIX_."meta (`id_meta`, `page`, `configurable`) VALUES (".$get_meta_id.", 'custompage', 1)"); You can also add cache clear to your script. Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); Tools::generateIndex(); Edited April 21, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Chill_user Posted April 21, 2020 Author Share Posted April 21, 2020 Wow, thanks a lot I will try this and tell the result here! Link to comment Share on other sites More sharing options...
Guest Posted April 21, 2020 Share Posted April 21, 2020 (edited) Here is my sample test module (without configuration) to create a test page "my-custom-page" URL: https://your-domain/my-custom-page custompage.zipFetching info... Edited May 1, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Verlonimo Posted May 4, 2020 Share Posted May 4, 2020 Hi, @Guest Custom controller works fine if extending file page... But is there a way to do same just for tpl file?Idea is to create a custom controller, add some code/variables and push to custom tpl. Then later include that file in other tpl's in template? Right now variables are shown only in that page/controller created. But if that tpl is included in different tpl it doesnt work... Thanks Link to comment Share on other sites More sharing options...
Guest Posted May 7, 2020 Share Posted May 7, 2020 (edited) Hi, @Verlonimo I have noticed in your other posts that you are smart enough to solve your own question. Edited May 7, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Verlonimo Posted May 7, 2020 Share Posted May 7, 2020 Hi, @Guest It's not about being smart enough. It's more about sharing your experience with community and other developers. Sometimes you can solve issue within 5 min. just asking for help instead of doing research for 2 or more days. Thanks Link to comment Share on other sites More sharing options...
MrEduar Posted January 18, 2021 Share Posted January 18, 2021 Amazing!! Thanks you @Guest Link to comment Share on other sites More sharing options...
Guest Posted January 19, 2021 Share Posted January 19, 2021 On 1/18/2021 at 5:00 PM, MrEduar said: Amazing!! Thanks you @Guest Expand I gladly helped 😉 Link to comment Share on other sites More sharing options...
mohammad zubair Posted December 24, 2021 Share Posted December 24, 2021 On 4/21/2020 at 5:52 AM, Guest said: Tutorial for Prestashop 1.7 1. create front controller <?php class custompageControllerCore extends FrontController { public $php_self = 'custompage'; public function initContent() { $this->context->smarty->assign( array( 'variable1' => 'Variable 1', 'variable2' => 'Variable 2', ) ); parent::initContent(); $this->setTemplate('custompage'); } } 2. save to ./controllers/front/custompageController.php 3. create tpl file {extends file='page.tpl'} {block name='page_title'} <span class="sitemap-title">{l s='Custom page' d='Shop.Theme'}</span> {/block} {block name='page_content'} <h2>My test page content</h2> <span>{$variable1}</span><br /> <span>{$variable2}</span><br /> {/block} 4. save to ./themes/your theme/templates/custompage.tpl 5. Admin -> Shop parameters -> Traffic & SEO 6. Click add new page 7. Select "Page name" custompage 8. Rewritten URL = my-custom-page 9. Save 10. Admin -> Advanced Parameters -> Performance 11. clear cache and recompile template 12. go to: https://your-store-url/my-custom-page 13. go to this post and like by clicking on the gray heart below the post 😉 Expand Link to comment Share on other sites More sharing options...
chinthaka sandaruwan Posted June 13, 2023 Share Posted June 13, 2023 On 4/21/2020 at 7:42 AM, Guest said: Here is my sample test module (without configuration) to create a test page "my-custom-page" URL: https://your-domain/my-custom-page custompage.zip 614.97 kB · 155 downloads Expand thank you very much, you save me. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now