Mambley Posted October 30, 2011 Share Posted October 30, 2011 Hi, How can i add the css class "active" when i am inside a CMS page? I know that in some pages i can use this: <a href="{$link->getPageLink('contact-form.php')}"{if $page_name == 'contact-form'} class="active"{/if}>Contact</a> But what i have to change in the following code to work the same way: <a href="{$link->getCMSLink('4', 'about-us')}">About us</a> Thanks. PS - Please move the topic if this is not the correct category. Link to comment Share on other sites More sharing options...
Anghel Posted October 30, 2011 Share Posted October 30, 2011 Hy Mambley. I was just searching for the same thing today. And found a way of doing that. It's not quite profesional..but it does the job. 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}> What we did so far is take the cms ID and add a class to the body tag. Now we need to add a class to the LI from the cms links, so we can make a css rule. Open blockcms.php find the function getCMStitles(). go to this line { $row['link'] = $link->getCMSLink((int)($row['id_cms']), $row['link_rewrite']); $links[] = $row; } Change it like this. { $row['link'] = $link->getCMSLink((int)($row['id_cms']), $row['link_rewrite']); $row['id_s'] = $row['id_cms']; $links[] = $row; } Now open Blockcms.tpl and add to the li a class {if isset($cms_page.link)}<li class="clink{$cms_page.id_s}"> And now use the css like this .... body.cms_class1 li.clink1 a { ***The desired css rule for active page*****} you can see it in action on this website that it;s still in development. http://biomio.studio...nt/4-despre-noi Link to comment Share on other sites More sharing options...
Mambley Posted October 30, 2011 Author Share Posted October 30, 2011 Hi Anghel, Thanks for your reply. I will try this and post the result later, but if you update prestashop then the changes will be lost right? Thanks again. Link to comment Share on other sites More sharing options...
Anghel Posted October 31, 2011 Share Posted October 31, 2011 yes that's write, on update all the modification are gone. you can try another way to do this without changing the displayHeader() function. By adding on the body tag {if $page_name =='cms'} class="cms{$smarty.get.id_cms}"{/if} This way you will modify only the blockcms.php Link to comment Share on other sites More sharing options...
Richard S Posted January 21, 2012 Share Posted January 21, 2012 You can override FrontController in PS 1.4 and above. You can find more information about that in the forum or Google. Then you will not have problems with updating your system or at least you will have less of them. Link to comment Share on other sites More sharing options...
tsmulugeta Posted February 11, 2012 Share Posted February 11, 2012 Open tmheaderlinks.tpl file. You can find it by going to modules > tmheaderlinks > tmheaderlinks.tpl on your website server. Then add this between <ul></ul> <li><a href="{$link->getCMSLink('35','health')}"{if {$smarty.server.REQUEST_URI} == '/35-health'} class="active"{/if}>{l s='Health Products' mod='tmheaderlinks'}</a></li> This will create a CMS link for you to a category called HEALTH with ID 35 and activate it when clicked. Link to comment Share on other sites More sharing options...
Mambley Posted March 15, 2012 Author Share Posted March 15, 2012 Open tmheaderlinks.tpl file. You can find it by going to modules > tmheaderlinks > tmheaderlinks.tpl on your website server. Then add this between <ul></ul> <li><a href="{$link->getCMSLink('35','health')}"{if {$smarty.server.REQUEST_URI} == '/35-health'} class="active"{/if}>{l s='Health Products' mod='tmheaderlinks'}</a></li> This will create a CMS link for you to a category called HEALTH with ID 35 and activate it when clicked. Hi, Thanks for your tip but its not working, when i enter in the CMS page, the active state don't work Link to comment Share on other sites More sharing options...
Mambley Posted March 15, 2012 Author Share Posted March 15, 2012 For now i found this solution. Since i am using 2 languages i need different urls (for SEO optimization) so what i did was: - go to /classes/FrontController.php and add my variable to smarty: (arround line 254) 'my_uri' => __PS_BASE_URI__.$ps_language->iso_code, This will output something like: http://domain.com/isocode - Then in my theme, in my case in tmheaderlinks i did this: <li> <a href="{$link->getPageLink('cms.php?id_cms=4')}"{if $smarty.server.REQUEST_URI == $my_uri|cat:'/content/4-quem-somos' or $smarty.server.REQUEST_URI == $my_uri|cat:'/content/4-about-us'} class="active"{/if}> {l s='about us' mod='tmheaderlinks'}</a> </li> In my case i have 2 different urls for "about us": - quem somos for portuguese; - about us for english; Now i have to find a way to optimize the code, like in href or for more languages can become a little confusing. Any suggestions? Thanks a lot. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now