Jump to content

How to add a custom page ?


Recommended Posts

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

  • Like 9
Link to comment
Share on other sites

  • 6 months later...

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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');

?> 

  • Sad 1
Link to comment
Share on other sites

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}
<
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 6 months later...
  • 5 months later...

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');
}

Link to comment
Share on other sites

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 (see edit history)
  • Like 11
Link to comment
Share on other sites

  • 3 months later...
  • 3 weeks later...

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

Link to comment
Share on other sites

  • 2 months later...

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 3 weeks later...

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 .

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...

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, [email protected] 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 (see edit history)
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 (see edit history)
Link to comment
Share on other sites

  • 1 month later...

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

  • 4 weeks later...

@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

  • Like 6
Link to comment
Share on other sites

  • 1 month later...

@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 (see edit history)
Link to comment
Share on other sites

  • 2 months later...

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'),
  ),
 ),

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

I have successfully created a custom page using your instructions, but now I am trying to create a 2nd custom page as I need two. You actually advised me on how to do this in v1.4 here

 

However I cannot get this to work on 1.5.4.

 

Here are the steps I have followed:

 

Can you please advise?

 

Thanks in advance...

 

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

 

NewPageController2.php

 

<?php
class NewPageController2Core 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_.'newpage2.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.

 

newpage2.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=newpage2'.($_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.

 

newpage2.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

Edited by glennlawre (see edit history)
Link to comment
Share on other sites

@glennlawre

 

Change

class NewPageController2Core extends FrontController

to

class NewPage2ControllerCore extends FrontController

 

So class name must end with ControllerCore.

I have tested this on fresh 1.5.4.0 and it works.

  • Like 1
Link to comment
Share on other sites

@razaro

 

 

Change

class NewPageController2Core extends FrontController

to

class NewPage2ControllerCore extends FrontController

 

So class name must end with ControllerCore.

I have tested this on fresh 1.5.4.0 and it works.

 

Worked great, thanks again...!

 

And I am on PS 1.5.4.0

 

One quick thing for anyone else that may get stuck on this, you need to make sure you name the "NewPageController.php" page the same as what you put in the string, e.g. if you have "NewPage2ControllerCore" in your string for an additional page, you also need to name the controller page "NewPage2ControllerCore.php" and place in the controllers/front directory.

 

But I'm sure most people will already know this... :)

Edited by glennlawre (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hi,

I am trying to create a new page following this thread too but i get an error "The website encountered an error while retrieving http://www.caprice-s...certificatcadou. It may be down for maintenance or configured incorrectly."

Here is what I did:

1. Created FrontController.php to override/classes/controller/front

<?php
class FrontController extends FrontControllerCore
{
public function init() {
			parent::init();
 $this--->context->smarty->assign('currentController', get_class($this));
}
}

2. Created certificatcadou.php in / :

require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();
Tools::redirect('index.php?controller=certificatcadou'.($_REQUEST ? '&'.http_build_query($_REQUEST, '', '&') : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');

3. Created certificatcadou.tpl in /themes/mytheme :

{include file="$tpl_dir./breadcrumb.tpl"}
{include file="$tpl_dir./errors.tpl"}
<h1>Testpage</h1>
controller: {$CertificatCadouController}

4. Created CertificatCadouController.php in /controllers/front/ :

<?php
class CertificatCadouControllerCore extends FrontController
{
public $php_self = 'certificatcadou';

public function initContent()
{
 parent::initContent();
 $this->setTemplate(_PS_THEME_DIR_.'certificatcadou.tpl');
}
}

5. Added In PS admin > Prefrences > SEO & URLs

Add new > Page = certificatcadou , Title = Certificat Cadou , Friendly URL = certificatcadou

 

Still no luck!!

Can you advise what could be wrong?

Robert

 

Edit: enabling error messaging I have found :

Fatal error: Class 'CertificatCadouController' not found in /home/sites/caprice-shop.ro/public_html/classes/controller/Controller.php on line 128

What is this? Shouls I move the new Controller file to /classes/controller/?

Edited by Caprice (see edit history)
Link to comment
Share on other sites

<?php
class FrontController extends FrontControllerCore
{
public function init() {
						    parent::init();
 $this--->context->smarty->assign('currentController', get_class($this));
}
}

 

Here you have $this--->context instead of $this->context .

 

Also you can move

 $this->context->smarty->assign('currentController', get_class($this));

to your CertificatCadouControllerCore init function.

  • Like 1
Link to comment
Share on other sites

<?php
class FrontController extends FrontControllerCore
{
public function init() {
							parent::init();
 $this--->context->smarty->assign('currentController', get_class($this));
}
}

 

Here you have $this--->context instead of $this->context .

 

Also you can move

 $this->context->smarty->assign('currentController', get_class($this));

to your CertificatCadouControllerCore init function.

 

Thanks razaro for trying to help!

The $this--->context was a small typo actually it is $this-->context sorry for misleading you.

But, I have moved

 $this->context->smarty->assign('currentController', get_class($this));

to CertificatCadouControllerCore init function which looks like this now:

[/color]
[color=#000000]class CertificatCadouControllerCore extends FrontController
{
public $php_self = 'certificatcadou';[/color]
[color=#000000]public function initContent()
{
 parent::initContent();
 $this->setTemplate(_PS_THEME_DIR_.'certificatcadou.tpl');
 $this->context->smarty->assign('currentController', get_class($this));
}
}

Still, no luck, I can't figure it out for my life!

Link to comment
Share on other sites

OK I tried on local server and found 2 issues.

Here are codes for files.

 

CertificatCadouController.php

<?php
class CertificatCadouControllerCore extends FrontController
{
public $php_self = 'certificatcadou';
public function initContent()
{
  parent::initContent();
  $this->context->smarty->assign('currentController', get_class($this));

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

 

certificatcadou.php (was missing <?php tag at beginning )

<?php
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();
Tools::redirect('index.php?controller=certificatcadou'.($_REQUEST ? '&'.http_build_query($_REQUEST, '', '&') : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');

 

certificatcadou.tpl (wrong variable name used)

{include file="$tpl_dir./breadcrumb.tpl"}
{include file="$tpl_dir./errors.tpl"}
<h1>Testpage</h1>
controller: {$currentController}

 

In controller variable currentController is assigned so that is used in tpl file.

 

This should work for you now.

  • Like 1
Link to comment
Share on other sites

OK I tried on local server and found 2 issues.

Here are codes for files.

 

CertificatCadouController.php

<?php
class CertificatCadouControllerCore extends FrontController
{
public $php_self = 'certificatcadou';
public function initContent()
{
  parent::initContent();
  $this->context->smarty->assign('currentController', get_class($this));

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

 

certificatcadou.php (was missing <?php tag at beginning )

<?php
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();
Tools::redirect('index.php?controller=certificatcadou'.($_REQUEST ? '&'.http_build_query($_REQUEST, '', '&') : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');

 

certificatcadou.tpl (wrong variable name used)

{include file="$tpl_dir./breadcrumb.tpl"}
{include file="$tpl_dir./errors.tpl"}
<h1>Testpage</h1>
controller: {$currentController}

 

In controller variable currentController is assigned so that is used in tpl file.

 

This should work for you now.

 

Changed all files as suggested, deleted cache, deleted class_index.php and now I have a redirect loop error at http://www.caprice-shop.ro/index.php?controller=certificatcadou

I have to check it further. Since it works for you it must be a problem with my configuration somehow.

Thank you for your patience!

Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...
  • 2 weeks later...

Will this sample code by razaro work on latest prestashop 1.5.6

 

this sample at http://nemops.com/creating-new-pages-in-prestashop/

 

gets installed. But when I try to configure, it throws error.

 

 

Also, the CMS module did not help me to place a flash object in the page.

 

Any help will be greatly appreciated

 

 

Regards, Stanley

Edited by JDStanley (see edit history)
Link to comment
Share on other sites

  • 1 month later...

This method works on 1.5.6.1 but you need to remember to delete "class_index.php" in root/cache folder after doing this.

 

Thanks Razaro!

 

@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

attachicon.gifcustomnewpage.PNG

 

Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...
  • 2 weeks later...

how you created this new page ?

you have to include your php code there (i bet that it's a php file)

In advance thanks for your consideration. actually I followed the 4 step mentioned in this topic(1.Create new controller for custom page2. ....). I tried to add my codes to controller.php but no results come true. I think my codes have some problem because as  u can see it is a combination of html and php together. 

Link to comment
Share on other sites

  • 1 month later...

not working for me in 1.6

 

code

 

mission.php in root

<?php
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();
Tools::redirect('index.php?controller=mission'.($_REQUEST ? '&'.http_build_query($_REQUEST, '', '&') : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');

controllers  MissionPageController.php

<?php
class MissionControllerCore extends FrontController
{
public $php_self = 'mission';
public function initContent()
{
   parent::initContent();
   $this->context->smarty->assign('mission', get_class($this));
  
   $this->setTemplate(_PS_THEME_DIR_.'mission.tpl');
}
}

and tpl file   mission.tpl in themes folder

include file="$tpl_dir./breadcrumb.tpl"}
{include file="$tpl_dir./errors.tpl"}
<h1>Mission</h1>
controller: {$currentController}


and then preferences -> SEO URL  see image attached

 

 

post-851402-0-77528600-1412620241_thumb.jpg

Edited by durangodave (see edit history)
Link to comment
Share on other sites

i also just attemped the CMS way.  And i can create the category in CMS no problem, but when i go to add a new page to the new category i get this, and i get this with or without tokens being enabled.

 

 

post-851402-0-91394600-1412626786_thumb.jpg

 

 

and fyi dont worry about the special coding from before with the new class, i removed it cause it was not working.  

Edited by durangodave (see edit history)
Link to comment
Share on other sites

For CMS error try this solution, from another topic http://www.prestashop.com/forums/topic/355328-solved-admin-cms-page-blank-token-error/?do=findComment&comment=1790068

 

But for sake of this topic, I have few things to add.

Php file in root is not needed anymore, maybe for some time. So in your case mission.php is not needed.

 

Then in mission.tpl code should be controller: {$mission} but that does not influence 404 error.

 

You could try to clear cache in back office ( Advanced parameter > Performance).

 

I got this

 

Edited by razaro (see edit history)
Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

Hey 

I want to add 1-2 customize page with coding in prestashop 1.6.0.11,  please give me sample file with instruction how to add that and customize that.

 

Somethings which i need in that customize page

1) I want a full width banner.

2) I want to add offers image in 4 to 6 groups with text bar above them differentiating each kind of offers, like this i want to add 16-25 images in one page. And i want that images can be change from the back-end(Admin-Panel) time to time.

3) with common footer.

 

Please help me 

Thanks in advance.

Link to comment
Share on other sites

As i told you I want to add following things:

1) I want a full width banner on top then.
2) I want to add offers image in 4 to 6 groups with text bar above them differentiating each kind of offers, like this i want to add 16-25 images in one page. And i want that images can be change from the back-end(Admin-Panel) time to time.
3) with common footer.

 

Please explain me how to make these things on new pages in prestashop.

Link to comment
Share on other sites

He did explained to you, you need to make custom module.

Module controller displays new custom page, you can add images in module back office configuration page.

Check out block banner module for adding full width banner at top, but limit just on that custom page.

Also check homeslider module for adding images, sorting them and so on.

 

If you are not developer you could ask in Job offers for quote.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

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

<?phpinclude(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.

 

 

Thank you Razaro. that was just what i wanted.

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

Good day everyone! I'm Ruel and just new to this forum. I just want to ask solution to my situation as I created a new page from CMS and I want it to appear to my footer and header of my website. My question is how can I make it appear to my footer and header of my website? Thanks in advance for all your help. GOD-speed! 

Link to comment
Share on other sites

  • 8 months later...
×
×
  • Create New...