Jump to content
  • 0
Sly Crespo

How to add a custom page ?

Question

Hello ! I'm new to PrestaShop and that question may be stupid.
I would like to add a custom page to my shop and a corresponding link on the top of the page. How do I do this ?
Thanks

Share this post


Link to post
Share on other sites

92 answers to this question

Recommended Posts

  • 0

You could go to Back Office » Tools » CMS and click on Add new.
And use some module to add it to homepage.

Another way is to create for example newpage.php

<?php

include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');

$smarty->display(_PS_THEME_DIR_.'newpage.tpl');

include(dirname(__FILE__).'/footer.php');

?>


and save it to main prestashiop folder and then in your theme folder create file newpage.tpl.


Both files are in attachment.

newpage.zip

Share this post


Link to post
Share on other sites
  • 0

Thanks razaro for your fast reply... But i'm a noob and don't know how to do that.. Can you explain it a little bit more precisely. Sorry about my english and Thanks.
Sly

Share this post


Link to post
Share on other sites
  • 0

You can add links to new pages with some modules, if you create CMS page you can use Info block module and if you created php page use Link block module.
And this module can do both.

Share this post


Link to post
Share on other sites
  • 0

I'm able to do what razaro suggested but I need that the page switches to a different language when the user click on the country flag. So 'newpage.php?id_lang=1' and 'newpage.php?id_lang=2' load the right translation of that page. Could you help me?

Share this post


Link to post
Share on other sites
  • 0

I don't know how you page looks like but for every text you display and want to be able to translate you need to use function l .

If you have php file

$this->l('Some text')


and in tpl file

{l s='Some text' }



And use translate tool in back office. That should be enough so when you change language text will change too.

Share this post


Link to post
Share on other sites
  • 0

Somehow, using {l s='Some text' } in my tpl file renders the code (it's a table with js animation) unreadable. Is there a way to just redirect to a different page based on language selection?

Share this post


Link to post
Share on other sites
  • 0

Try to add this code

include(dirname(__FILE__).'/init.php');



So page looks like

<?php

include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');

include(dirname(__FILE__).'/header.php');

$smarty->display(_PS_THEME_DIR_.'newpage.tpl');

include(dirname(__FILE__).'/footer.php');

?> 

Share this post


Link to post
Share on other sites
  • 0

My .php page already has this code in it

$smarty->display(_PS_THEME_DIR_.'newpage.tpl');



I think the problem is in inserting the js into the header

[removed][removed]
[removed][removed]



I'm not sure where this goes to be read. This is what my header.tpl looks like.

>

<html >
   <head>
       <title>{$meta_title|escape:'htmlall':'UTF-8'}</title>
{if isset($meta_description) AND $meta_description}
       <meta name="description" content="{$meta_description|escape:html:'UTF-8'}" />
{/if}
{if isset($meta_keywords) AND $meta_keywords}
       <meta name="keywords" content="{$meta_keywords|escape:html:'UTF-8'}" />
{/if}
       <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
       <meta name="generator" content="PrestaShop" />
       <meta name="robots" content="{if isset($nobots)}no{/if}index,follow" />
       <link rel="icon" type="image/vnd.microsoft.icon" href="{$img_ps_dir}favicon.ico" />
       <link rel="shortcut icon" type="image/x-icon" href="{$img_ps_dir}favicon.ico" />
{if isset($css_files)}
   {foreach from=$css_files key=css_uri item=media}
   <link href="{$css_uri}" rel="stylesheet" type="text/css" media="{$media}" />
   {/foreach}
{/if}
       [removed][removed]
       [removed]
           var baseDir = '{$content_dir}';
           var static_token = '{$static_token}';
           var token = '{$token}';
           var priceDisplayPrecision = {$priceDisplayPrecision*$currency->decimals};
           var roundMode = {$roundMode};
       [removed]
       [removed][removed]
       [removed][removed]
       [removed][removed]

{if isset($js_files)}
   {foreach from=$js_files item=js_uri}
   [removed][removed]
   {/foreach}
{/if}
       {$HOOK_HEADER}
   </head>

   <body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}>
   {if !$content_only}
</pre>
<ul>{l s='This shop requires JavaScript to run correctly. Please activate JavaScript in your browser.'}</ul>
<br><div>

           <!-- Header -->




                       {$HOOK_TOP}




           <!-- Center -->



   {/if}
<

Share this post


Link to post
Share on other sites
  • 0

Could you zip relevant files (newpage tpl header tpl ..) and attach it to your post?

If you use some custom js code surround it with

 {literal} .....{/literal}



Also to turn debug mode on change in config/config.inc.php

/* Debug only */
@ini_set('display_errors', 'on');


to help you find any errors you might have.

Share this post


Link to post
Share on other sites
  • 0

Basically, this is what I'm trying to implement in the newpage.tpl

http://css-tricks.com/examples/InfoGrid/

I'm currently loading the page with an iframe. It works but I'd like something smoother.

Whenever I try to call a javascript file, it seems to break the js for the whole page so I must be doing it wrong or putting it in the wrong location.

Share this post


Link to post
Share on other sites
  • 0

Hi,
I'm using the theme of healthy. TemplateMonster 32552, newpage.tpl and newpage.php files installed. But another process to create a new page than I do myself?
note: the theme to activate it, I am installing dump.sql file.

Share this post


Link to post
Share on other sites
  • 0

I am trying to add some js to this test file. I know i can put.

 

<script language="javascript" src="testjsfile.js">
</script>


 

But how would i include it so CCC will include it?

 

in a modual i know i would do it this way.

 

public function hookHeader($params)
{
 Tools::addJS(($this->_path).'testjsfile.js');
}

Share this post


Link to post
Share on other sites
  • 0

One way to create new custom page in version 1.4.x is :

 

1.Create new controller for custom page.

 

NewPageController.php

<?php

class NewPageControllerCore extends FrontController
{
 public $php_self = 'new-page.php';

 public function setMedia()
 {
	  parent::setMedia();
	  Tools::addCSS(_THEME_CSS_DIR_.'new-page.css');
	  Tools::addJS(_THEME_JS_DIR_.'new-page.js');
 }

 public function displayContent()
 {
	   parent::displayContent();
	   self::$smarty->display(_PS_THEME_DIR_.'new-page.tpl');
 }
}

 

NewPageController.php should be placed in controllers folder.

In function setMedia() js ad css files are called from theme directory js and css folders for example,

but here also can be used _PS_CSS_DIR_ and _PS_JS_DIR_ for calling files from root

js and css directories.

 

 

 

2.Create new custom page

 

new-page.php

<?php

require(dirname(__FILE__).'/config/config.inc.php');
ControllerFactory::getController('NewPageController')->run();

 

 

new-page.php should be placed in root directory (with the rest of php files)

 

3.Create tpl file for new page

 

new-page.tpl

 

{capture name=path}{l s='NewPage'}{/capture}
{include file="$tpl_dir./breadcrumb.tpl"}

<h1>{l s='Custom new page'}</h1>

 

new-page.tpl should be placed in theme folder.

 

And that is not too hard, right :-)

And replace NewPage and new-page with page name you want.

Just follow class NewPageControllerCore -> getController('NewPageController'),

new-page.php -> new-page.tpl.

 

One more thing do is in Back Office > Preferences > SEO & URLs , click on Add new,

select custom new page (new-page.php) and fill rest of data and regenerate .htaccess file.

Then instead going to website.com/new-page.php for example following could be used

website.com/custom-new-page .

Edited by razaro

Share this post


Link to post
Share on other sites
  • 0

Hi razaro,

 

Thanks for the guide, I have followed the instructions and was able to create a new page. However, the content I entered from the tpl file is not displayed. Also I will like to be able to edit the content from back office

Share this post


Link to post
Share on other sites
  • 0

Thanks so much. It works great for me, but what does it mean:

{capture name=path}{l s='NewPage'}{/capture}

It is for breadcrumbs.

 

actually for some reason, when I try to add additional content, it doesn't show it. I wonder why?

When editing tpl files Force Compile option needs to be set to ON,

in Back office > Preferences > Performance

Share this post


Link to post
Share on other sites
  • 0

Hm I have the problem where nothing shows, any idea what that could be?

 

Hi bafke,

As mentioned above, please ensure that you have Force Compile turned on and Cache turned off in your Back Office under Preferences > Performance, and also be sure to clear your browser's cache.

 

I hope this helps.

 

-Mike

Share this post


Link to post
Share on other sites
  • 0

Hi bafke,

As mentioned above, please ensure that you have Force Compile turned on and Cache turned off in your Back Office under Preferences > Performance, and also be sure to clear your browser's cache.

 

I hope this helps.

 

-Mike

 

Ah yes that I had, the problem tho was a typo in the controller file :P

Share this post


Link to post
Share on other sites
  • 0

Hi,

 

I created a new custom page using the method as described below by razaro. Everything works, except the Page Title doesn't appear at the top of the browserpage. Even when I copy the exact new-page example, the Page Title doesn't work. I change the page title in Backoffice - Preferences - SEO & Urls and have regenerated the .htaccess file.

 

In the past, I've created custom pages by only generating a .php and .tpl file (http://www.prestashop.com/forums/topic/49131-how-to-edit-the-html-source-of-a-cms-generated-page/) which worked fine too, but again, I never managed to be able to change the page title.

 

Am running Prestashop 1.4.4.1.

 

I'm struggling with this for quite some time already, any advice or ideas are highly appreciated!

 

Thanks

 

One way to create new custom page in version 1.4.x is :

 

1.Create new controller for custom page.

 

NewPageController.php

<?php

class NewPageControllerCore extends FrontController
{
 public function setMedia()
 {
	  parent::setMedia();
	  Tools::addCSS(_THEME_CSS_DIR_.'new-page.css');
	  Tools::addJS(_THEME_JS_DIR_.'new-page.js');
 }

 public function displayContent()
 {
	   parent::displayContent();
	   self::$smarty->display(_PS_THEME_DIR_.'new-page.tpl');
 }
}

 

NewPageController.php should be placed in controllers folder.

In function setMedia() js ad css files are called from theme directory js and css folders for example,

but here also can be used _PS_CSS_DIR_ and _PS_JS_DIR_ for calling files from root

js and css directories.

 

 

 

2.Create new custom page

 

new-page.php

<?php

require(dirname(__FILE__).'/config/config.inc.php');
ControllerFactory::getController('NewPageController')->run();

 

 

new-page.php should be placed in root directory (with the rest of php files)

 

3.Create tpl file for new page

 

new-page.tpl

 

{capture name=path}{l s='NewPage'}{/capture}
{include file="$tpl_dir./breadcrumb.tpl"}

<h1>{l s='Custom new page'}</h1>

 

new-page.tpl should be placed in theme folder.

 

And that is not too hard, right :-)

And replace NewPage and new-page with page name you want.

Just follow class NewPageControllerCore -> getController('NewPageController'),

new-page.php -> new-page.tpl.

 

One more thing do is in Back Office > Preferences > SEO & URLs , click on Add new,

select custom new page (new-page.php) and fill rest of data and regenerate .htaccess file.

Then instead going to website.com/new-page.php for example following could be used

website.com/custom-new-page .

Share this post


Link to post
Share on other sites
  • 0

try adding

public $php_self = 'newpage.php';

above function setMedia() in NewPageController.php

 

Yes that line is missing, thanks sixthmind.

Share this post


Link to post
Share on other sites
  • 0

Hi,

 

I have followed the same steps but I also have same problem that content is not displaying on frontend. Can anyone please help me out for this?

Share this post


Link to post
Share on other sites
  • 0

Hi,

 

can anyone tell me how can I make custom page SEO friendly, actually its a little complicated then what has been discussed so far on this topic.

 

What i want is on a custom page I want to display testimonials which are managed through a module and on the same page user can add testimonials using a form.

 

What I have done so far is I am able to show testimonials which are added and form also the only problem i am facing as website is using SEO friendly url so when i try to add anything using that form it shows 404 error because I have addressed a php file in action of the form.

 

How can I solve this option is there any better option to do so?

 

Thanks,

Wajiha

Share this post


Link to post
Share on other sites
  • 0

I did all the above but I still get a 404 error 500 Internal Error when I try to acces my php file. Can you help me? I run on Prestashop 1.4.8.2.

 

Anyone has any ideas? Thanks in advance...

Edited by tudorached

Share this post


Link to post
Share on other sites
  • 0

Can you send me your files/code by PM and do you have link to your website ?

 

 

I can tell you my process:

 

1.I've added new-page.php in the main folder, near the rest of the php files

 

<?php



require(dirname(__FILE__).'/config/config.inc.php');


ControllerFactory::getController('NewPageController')->run();

 

2. I've added NewPageController.php in the controllers folder, near the rest of controllers

 

<?php

class NewPageControllerCore extends FrontController
{
 public $php_self = 'new-page.php';

 public function setMedia()
 {
			  parent::setMedia();
			  Tools::addCSS(_THEME_CSS_DIR_.'new-page.css');
			  Tools::addJS(_THEME_JS_DIR_.'new-page.js');


 }
 public function displayContent()
 {
			   parent::displayContent();
			   self::$smarty->display(_PS_THEME_DIR_.'new-page.tpl');
 }
}

 

3. I've added new-page.tpl in my theme's folder

 

{capture name=path}{l s='NewPage'}{/capture}
{include file="$tpl_dir./breadcrumb.tpl"}
<h1>{l s='Custom new page'}</h1>

 

4. In my admin interface Prefferences -> SEO&URLs I've added new-page.php

 

5. I've generated a new .htaccess in admin interface Tools -> Generators

 

6. I try to access the new-page by using the address http://www.mydomain.com/new-page.php or http://www.mydomain.com/new-page and i get 500 Internal Error

 

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@nutrizzia.goodafternoon.ro and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

 

I've looked in the .htaccess file to see if it's updated and there I can find the line

RewriteRule ^new-page$ /new-page.php [QSA,L]

 

Thank you for helping me.

 

 

ps: I've also checked in Back office > Preferences > Performance

 

Force Compile is enabled and Cache disabled.

Edited by tudorached

Share this post


Link to post
Share on other sites
  • 0

Code seems fine.

Could you try to enable debug mode and/or dev mode to see if it will display some specific error.

 

config.inc.php

/* Debug only */
@ini_set('display_errors', 'on');

 

defines.inc.php

define('_PS_MODE_DEV_', true);

 

And also in your hosing Cpanel check apache error log

Share this post


Link to post
Share on other sites
  • 0

And also in your hosing Cpanel check apache error log

 

Thanks to your advice I've solved it.

 

After looking in the apache error log I've found the error

 SoftException in Application.cpp:256: File "....../new-page.php" is writeable by group 

.

 

Somehow the php file had all the writing permissions checked and the server didn't allow it to be accessed. I've left enabled just the user writing access and now it works just fine.

 

Thank you again.

Edited by tudorached

Share this post


Link to post
Share on other sites
  • 0

One way to create new custom page in version 1.4.x is :

 

1.Create new controller for custom page.

 

NewPageController.php

<?php

class NewPageControllerCore extends FrontController
{
 public $php_self = 'new-page.php';

 public function setMedia()
 {
	  parent::setMedia();
	  Tools::addCSS(_THEME_CSS_DIR_.'new-page.css');
	  Tools::addJS(_THEME_JS_DIR_.'new-page.js');
 }

 public function displayContent()
 {
	   parent::displayContent();
	   self::$smarty->display(_PS_THEME_DIR_.'new-page.tpl');
 }
}

 

NewPageController.php should be placed in controllers folder.

In function setMedia() js ad css files are called from theme directory js and css folders for example,

but here also can be used _PS_CSS_DIR_ and _PS_JS_DIR_ for calling files from root

js and css directories.

 

 

 

2.Create new custom page

 

new-page.php

<?php

require(dirname(__FILE__).'/config/config.inc.php');
ControllerFactory::getController('NewPageController')->run();

 

 

new-page.php should be placed in root directory (with the rest of php files)

 

3.Create tpl file for new page

 

new-page.tpl

 

{capture name=path}{l s='NewPage'}{/capture}
{include file="$tpl_dir./breadcrumb.tpl"}

<h1>{l s='Custom new page'}</h1>

 

new-page.tpl should be placed in theme folder.

 

And that is not too hard, right :-)

And replace NewPage and new-page with page name you want.

Just follow class NewPageControllerCore -> getController('NewPageController'),

new-page.php -> new-page.tpl.

 

One more thing do is in Back Office > Preferences > SEO & URLs , click on Add new,

select custom new page (new-page.php) and fill rest of data and regenerate .htaccess file.

Then instead going to website.com/new-page.php for example following could be used

website.com/custom-new-page .

 

This worked great for me thanks...

 

Can you please advise how it is possible to add multiple custom pages?

 

Can you add detail to the same NewPageController.php to call additional custom pages, or do you need a seperate NewPageController.php for each custom page?

 

Thanks...

Share this post


Link to post
Share on other sites
  • 0

This way is meant to be be used when you need to make one custom page with it's own css and js files.

For multiple custom pages you will need to repeat whole thing for each page which is not too good.

 

You should try to use CMS pages feature of Prestashop if you can.

If not there is option to override CMSController or to make custom module to match you needs.

Share this post


Link to post
Share on other sites
  • 0

I did try to replicate what I did for a second page, but this did not work for me.

 

I did the following:

 

NewPageController2.php - I named this "NewPageController2"

<?php

 

class NewPageControllerCore extends FrontController

{

public $php_self = 'new-page2.php';

 

public function setMedia()

{

parent::setMedia();

Tools::addCSS(_THEME_CSS_DIR_.'new-page.css');

Tools::addJS(_THEME_JS_DIR_.'new-page.js');

}

 

public function displayContent()

{

parent::displayContent();

self::$smarty->display(_PS_THEME_DIR_.'new-page2.tpl');

}

}

 

NewPageController2.php was placed in controllers folder.

I used the same .css & .js for this page.

 

 

 

2.Create new custom page

 

new-page2.php

<?php

 

require(dirname(__FILE__).'/config/config.inc.php');

ControllerFactory::getController('NewPageController2')->run();

 

 

new-page2.php was placed in root directory (with the rest of php files)

 

3.Create tpl file for new page

 

new-page2.tpl

 

{capture name=path}{l s='NewPage2'}{/capture}

{include file="$tpl_dir./breadcrumb.tpl"}

 

<h1>{l s='Custom new page'}</h1>

 

new-page2.tpl was placed in the theme directory.

 

Can you tell me where I am going wrong?

 

I really only need two of these custom pages so this is probably the easiest way to do it. CMS page won't really work with the way I want to controll the layout/functions of the page etc.

 

Thanks...

Share this post


Link to post
Share on other sites
  • 0

ok i find the solution but i have a problem with redirection its meen iam still redirect to index.php?controller=page.php

i added the rules in backoffice but without any result ..

thank you

Share this post


Link to post
Share on other sites
  • 0

@radovan had trouble with that also and I think problem is in name "new-page" don't work but "newpage" do. Reason is maybe somewhere in code controller name is searched using regular expression but "-" is missed.

 

So here is complete code to adding new, custom page to version 1.5.

 

1.Create new controller for custom page. It should be placed in root directory > controllers/front folder.

 

NewPageController.php

 

<?php
class NewPageControllerCore extends FrontController
{
public $php_self = 'newpage';
public function setMedia()
{
 parent::setMedia();
 $this->addCSS(_THEME_CSS_DIR_.'newpage.css');
 $this->addJS(_THEME_JS_DIR_.'newpage.js');
}
public function initContent()
{
 parent::initContent();

 $this->setTemplate(_PS_THEME_DIR_.'newpage.tpl');
}
}

 

Note that js and css file are added just for an example. If not needed whole function setMedia() could be left out.

 

2.Create new custom page in root directory.

 

newpage.php

 

<?php
/**
* This file will be removed in 1.6
* You have to use index.php?controller=page_name instead of this page
*
* @deprecated 1.5.0
*/
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();
Tools::redirect('index.php?controller=newpage'.($_REQUEST ? '&'.http_build_query($_REQUEST, '', '&') : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');

 

3.Create tpl file for new page and place it in theme folder.

 

newpage.tpl

 

{capture name=path}{l s='CustomNewPage'}{/capture}
{include file="$tpl_dir./breadcrumb.tpl"}
<h1>{l s='Custom new page'}</h1>

 

4. Last step is to add new page in Preferences > SEO & URLs

 

post-45807-0-95663100-1351069405_thumb.png

Share this post


Link to post
Share on other sites
  • 0

@radovan had trouble with that also and I think problem is in name "new-page" don't work but "newpage" do. Reason is maybe somewhere in code controller name is searched using regular expression but "-" is missed.

 

So here is complete code to adding new, custom page to version 1.5.

 

1.Create new controller for custom page. It should be placed in root directory > controllers/front folder.

 

NewPageController.php

 

<?php
class NewPageControllerCore extends FrontController
{
public $php_self = 'newpage';
public function setMedia()
{
 parent::setMedia();
 $this->addCSS(_THEME_CSS_DIR_.'newpage.css');
 $this->addJS(_THEME_JS_DIR_.'newpage.js');
}
public function initContent()
{
 parent::initContent();

 $this->setTemplate(_PS_THEME_DIR_.'newpage.tpl');
}
}

 

Note that js and css file are added just for an example. If not needed whole function setMedia() could be left out.

 

2.Create new custom page in root directory.

 

newpage.php

 

<?php
/**
* This file will be removed in 1.6
* You have to use index.php?controller=page_name instead of this page
*
* @deprecated 1.5.0
*/
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();
Tools::redirect('index.php?controller=newpage'.($_REQUEST ? '&'.http_build_query($_REQUEST, '', '&') : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');

 

3.Create tpl file for new page and place it in theme folder.

 

newpage.tpl

 

{capture name=path}{l s='CustomNewPage'}{/capture}
{include file="$tpl_dir./breadcrumb.tpl"}
<h1>{l s='Custom new page'}</h1>

 

4. Last step is to add new page in Preferences > SEO & URLs

 

post-45807-0-95663100-1351069405_thumb.png

 

thanks,this is exactly what I want!

Edited by infoseek

Share this post


Link to post
Share on other sites
  • 0

Thanks @razaro just what i was looking for.

 

And you don't need to Create a new custom page in root directory newpage.php

 

if you need seo urls for your newpage like: newpage/newnewpage

 

override the Dispatcher.php

 

 'newpage_rule' => array(
  'controller' => 'newpage',
  'rule' =>  'newpage{/:info}',
  'keywords' => array(
   'info' =>  array('regexp' => '[_a-zA-Z0-9-\pL]*', 'param' => info'),
  ),
 ),

Share this post


Link to post
Share on other sites

×