Jump to content

Adding CMS Page ID's to class Selector in Body Tag


Cehrlichman

Recommended Posts

Today I was looking for a good solution to add a class sector to my body tag that would display the CMS page ID's. My goal was to create custom styles for individual CMS pages.

 

If you've ever tried to use styles within a CMS page you know that the editor strips out the <style> html code. Now I know there's most likely a fix to allow these html code to be used within the editor, but I figured this fix would allow for more flexibility with design.

 

Below are the steps I used to accomplish this.

 

Currently using PrestaShop Version 1.4.7

 

 

Longhand Method - Original Post

 

Step 1 - Open classes/FrontController.php

 

Replace line 475

'content_only' => (int)Tools::getValue('content_only')

 

with

'content_only' => (int)Tools::getValue('content_only'),
'cms_class' =>(int)Tools::getValue('id_cms')

 

 

Step 2 - Open themes/(yourtheme)/header.tpl

 

Replace line (465 [may very depending on theme])

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}>

 

with

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}" {/if} {if $page_name =='cms'} class="cms{$cms_class}"{/if}>

 

That's it! Now you should see body tags on CMS pages that look something like this.

<body class="cms7" id="cms">

 

 

Edit: After making this post both vekia & Burhan BVK pointed out there is a much easier and simple way to accomplish what is above. Below is the shorthand version accomplishing the same task; adding CMS page ID's to class Selector. Thanks vekia & Burhan BVK!

 

1 Step Method - Open themes/(yourtheme)/header.tpl

 

Replace line (465 [may very depending on theme])

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}>

 

with

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}" {/if} {if $page_name =='cms' && Tools::getValue('id_cms')}class="cms{Tools::getValue('id_cms')}"{/if}>

 

That's it! Now you should see body tags on CMS pages that look something like this.

<body class="cms7" id="cms">

 

 

Hope this helps. Please let me know if you have any question.

Edited by Cehrlichman (see edit history)
  • Like 1
Link to comment
Share on other sites

you can do the same without core modification, just one line:

{if $page_name =='cms'}cms{Tools::getValue('id_cms')}{/if}

 

You also need to check the id:

{if $page_name =='cms' && Tools::getValue('id_cms')}cms{Tools::getValue('id_cms')}{/if}

 

Cms category pages have the same page name (cms) but use a different id (id_cms_category).

Edited by Burhan BVK (see edit history)
  • Like 2
Link to comment
Share on other sites

it is necessary to use class selector based on link_rewrite value?

I just wondering why.

 

Mainly because you can use also category id for this

class="{if $page_name =='cms' && Tools::getValue('id_cms')}classcms{Tools::getValue('id_cms')}{/if}"

 

id_cms is also unique, the same as the link_fewrite field

 

hmmm?

Link to comment
Share on other sites

  • 7 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...