NeilD Posted November 7, 2011 Share Posted November 7, 2011 [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 More sharing options...
NeilD Posted November 7, 2011 Author Share Posted November 7, 2011 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 More sharing options...
markanthony1986 Posted April 18, 2012 Share Posted April 18, 2012 Nicely! 'cms_class' =>(int)Tools::getValue('id_cms'), Don't forget to add the comma at the end.. Link to comment Share on other sites More sharing options...
papertraitors Posted January 11, 2013 Share Posted January 11, 2013 (edited) 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 January 11, 2013 by papertraitors (see edit history) Link to comment Share on other sites More sharing options...
wfpaisa Posted March 6, 2013 Share Posted March 6, 2013 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 More sharing options...
Recommended Posts