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

×