Tales
Tales

Reputation: 1923

Create new template for CMS pages in prestashop

I have several pages created under the Preferences -> CMS which are ok. Now I need to create some more pages that will have a different look, is there a way to add like a different template and use the same CMS interface to do it?. I was thinking of something like:

Step 1. Create new cms-2.tpl Step 2. Modify the database to add a new "template" field Step 3. Modify the back office to add an extra field to the CMS page to choose the template to be used with the CMS page

So far I have been reading about "Creating pages without CMS" like in this link: Custom page in Prestashop 1.6 without CMS or this other link: Create custom page in Prestashop 1.5.3, but none of them seem to be what i am looking for.

Thanks

Upvotes: 2

Views: 5602

Answers (2)

Jack Wire
Jack Wire

Reputation: 721

Update for prestashop 1.7

You don't need to override the cms controller anymore. This function is already written by default.

You can just create a page-ID.tpl in your themes/your-theme/templates/cms folder. Where ID is the cms page ID.

Upvotes: 5

fana
fana

Reputation: 373

This worked for Prestashop 16.0.14:

Copy /controllers/front/CmsController.php to /override/controllers/front/CmsController.php and find the last method of the class, which is initContent().

The last line is $this->setTemplate(_PS_THEME_DIR_.'cms.tpl');. Change it to:

if(is_file(_PS_THEME_DIR_.'cms-'.$this->cms->id.'.tpl')){
    $this->setTemplate(_PS_THEME_DIR_.'cms-'.$this->cms->id.'.tpl');
}
else{
    $this->setTemplate(_PS_THEME_DIR_.'cms.tpl');
}

Then you need to delete the file /cache/class_index.php to force cache recreation.

Then you can create files inside your theme folder like this: cms-2.tpl where 2 is the id from your CMS page (just duplicate cms.tpl and change filename). Make sure you keep your cms.tpl as a fallback to all other CMS pages.

Upvotes: 4

Related Questions