Jump to content

cms body class id's


Recommended Posts

[solved]

 

Is there any way to add the page ID as a body class so that each CMS page can have its own background image?

 

at the moment code for all cms pages is generated as:

 

<body id="cms">

 

I'd like to make it different for each CMS page. i'm sure adding the page ID as a class or as part of the body id would be relatively simple but its beyond my coding skills.

 

there is a similar thread here:

 

http://www.prestasho...s-on-cms-pages/

 

But it is for an older version of presta and i can't get it to work.

 

All help is much appreciated.

 

Many thanks in advance

Link to comment
Share on other sites

after further googleing i found this solution by Anghel on this forum.

 

Open classes/FrontController.php

Find the function displayHeader()

 

After this

'logo_image_height' => Configuration::get('SHOP_LOGO_HEIGHT'),
  'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_,
  'content_only' => (int)Tools::getValue('content_only'),

 

Add this line of code

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

 

Open Header.tpl

add in the body tag this line of code {if $page_name =='cms'} class="cms{$cms_class}"{/if}

like this

 

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

Link to comment
Share on other sites

  • 5 months later...
  • 8 months later...

Thank you NeilD! the solution worked great

 

I'm using version 1.5.2 so this is how I used your solution

 

in themes/[my_theme]/header.tpl my body tag had to be slightly edited as both id and class already had values (default prestashop theme) with the addition of the code above it now is:

 

<body {if isset($page_name)}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if} class="{if $page_name =='cms'}cms{$cms_class}{/if} {if $hide_left_column}hide-left-column{/if} {if $hide_right_column}hide-right-column{/if}">

 

 

and the php

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

was entered into prestashop/override/classes/controller/FrontController.php

 

I simply copied the whole function over from prestashop/classes/controller/FrontController.php so now my override version looks like:

 

<?php
class FrontController extends FrontControllerCore
{
public function initHeader()
{
 // P3P Policies (http://www.w3.org/TR/2002/REC-P3P-20020416/#compact_policies)
 header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"');
 /* Hooks are volontary out the initialize array (need those variables already assigned) */
 $this->context->smarty->assign(array(
  'time' => time(),
  'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
  'static_token' => Tools::getToken(false),
  'token' => Tools::getToken(),
  'logo_image_width' => Configuration::get('SHOP_LOGO_WIDTH'),
  'logo_image_height' => Configuration::get('SHOP_LOGO_HEIGHT'),
  'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_,
  'content_only' => (int)Tools::getValue('content_only'),
  'logo_url' => _PS_IMG_.Configuration::get('PS_LOGO').'?'.Configuration::get('PS_IMG_UPDATE_TIME'),
  'favicon_url' => _PS_IMG_.Configuration::get('PS_FAVICON'),
  'cms_class' =>(int)Tools::getValue('id_cms'),
 ));
}
}

 

hope this helps those that find this thread

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

  • 1 month later...

only

 

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if} {if $smarty.get.id_cms}class="cmsok cms{$smarty.get.id_cms}"{/if} {if $smarty.get.id_cms_category}class="cmscatok cms_cat{$smarty.get.id_cms_category}"{/if}>

Link to comment
Share on other sites

×
×
  • Create New...