sixthmind Posted February 24, 2012 Share Posted February 24, 2012 I would like to add class 'selected' to 'a' and I've noticed this principle for Categories block. I would like to do the same for CMS block, but not sure how. Under category-tree-branch.tpl we have this code that produces 'selected' class when necessary: [list] [*] [b][url="{$node.link}"]{$node.name|escape:html:'UTF-8'}[/url][/b] {if $node.children|@count > 0} [list] {foreach from=$node.children item=child name=categoryTreeBranch} {if isset($smarty.foreach.categoryTreeBranch) && $smarty.foreach.categoryTreeBranch.last} {include file="$branche_tpl_path" node=$child last='true'} {else} {include file="$branche_tpl_path" node=$child last='false'} {/if} {/foreach} [/list] {/if} How would I do something similar in blockcms.tpl? Any ideas? what is the correct variable for current cms id and what does $node variable means? Could anybody explain if the code above could be adapted to be used for cms block (if statement for selected class)? 1 Link to comment Share on other sites More sharing options...
sixthmind Posted February 27, 2012 Author Share Posted February 27, 2012 I've been trying to find solution online, but no luck just yet. I have a CMS category with CMS pages underneath and once we are on particular page I want it to have class 'selected'. Anybody please? How would I use the following code that is used for categories on CMS pages? <a href="{$node.link}" {if isset($currentCategoryId) && ($node.id == $currentCategoryId)}class="selected"{/if} title="{$node.desc|strip_tags:false|escape:html:'UTF What is this $node variable? Can anybody explain please? 1 Link to comment Share on other sites More sharing options...
Rémy Posted February 27, 2012 Share Posted February 27, 2012 Hello Sixtmind, Funny : This afternoon I was looking for... the same thing... I didn't found the totaly response but here is some news : {if isset($currentCategoryId) && ($cms_page.id_cms == $currentCategoryId)}class="selected"{/if} You have to replace "$node.id" by "$cms_page.id_cms". I have tested it, it returns the good cms-page-id. BUT, what I am looking for now, is the good "current-cms-page-id" to replace "$currentCategoryId" wich doesn't returns the good id in this if-test (in fact, no id is returned by this "$currentCategoryId" in CMS pages). If I find it before YOU find it, I'll tell you. And if You find it before I find it, don't forget to tell me... (sorry about my approximativ English...) Link to comment Share on other sites More sharing options...
Rémy Posted February 27, 2012 Share Posted February 27, 2012 Hello again, I found the solution => "$smarty.get.id_cms" !!! The good code is : <li><a href="{$cms_page.link}" {if isset($smarty.get.id_cms) && ($cms_page.id_cms == $smarty.get.id_cms)}class="selected"{/if} title="{$cms_page.meta_title|escape:html:'UTF-8'}">{$cms_page.meta_title|escape:html:'UTF-8'}</a></li> You just have to add the following code in your "global.css" 's Theme : div.block a.selected { color:#e36731; font-weight:bold; } Tell me if it's ok for you to. Bye, Rémy. 3 Link to comment Share on other sites More sharing options...
sixthmind Posted February 28, 2012 Author Share Posted February 28, 2012 Thanks Remy for sharing your solution and I am glad you made yours work. I tried your code on my website, but unfortunately it doesn't do exactly what I would like. Basically I have a 3 CMS blocks in the left column. Each block has pages within in and when I put the code that you used, what it does: it gives all the top pages (CMS categories) class 'selected'. I am still trying to figure how how to give class 'selected' only to the page we are currently on - basically when we are viewing CMS category page. Edit: Actually it doesn't work at all now, the class selected was added by another code. Your code doesn't do anything on mine. I am looking what the problem is now. Link to comment Share on other sites More sharing options...
sixthmind Posted February 28, 2012 Author Share Posted February 28, 2012 When it comes to highlighting a menu item, I understand that we need to get a URL of a current page like here: http://www.prestasho...f-current-page/ There is also a smarty variable: {* display value of page from URL ($_GET) http://www.example.c...ex.php?page=foo *} {$smarty.get.page} but this doesn't seem to work in .tpl files? Once we have a current page URL, we then check if href value is the same as current page URL. If it is, we add class selected. Now, this is theory, but how to do it in practice? I've tried: {if $smarty.get.page == $cms_page.link}class="selected"{/if} This doesn't work. I am using this code in blockcms.tpl Another variable is: $smarty.server.REQUEST_URI which I am not sure how to use. Link to comment Share on other sites More sharing options...
John_John Posted March 22, 2012 Share Posted March 22, 2012 Hi sixthmind, Did you have any luck with this? Basically what i am curious about is... can i add certain CMS pages to blocktopcategories.tpl but while also maintaining the "selected" class when a CMS page is active Please let me know Link to comment Share on other sites More sharing options...
Emmanuel Paris Posted March 23, 2012 Share Posted March 23, 2012 Not the perfect solution because you will have to hardcode each link but you could try : {if $request_uri|strstr:"8"}class="selected"{/if} where 8 is the ID of your CMS page... 1 Link to comment Share on other sites More sharing options...
John_John Posted March 24, 2012 Share Posted March 24, 2012 Hi Emmanuel, Thanks for your reply. Although it does work, but i have a combination of CMS pages and the categories, meaning that if i have 1 category page selected and try to open a CMS page, the CMS page link does get selected, but the other category page still remains selected. Is there a way to de-select all the others and have only 1 'selected'? Link to comment Share on other sites More sharing options...
bogdan90i Posted October 10, 2014 Share Posted October 10, 2014 Not the perfect solution because you will have to hardcode each link but you could try : {if $request_uri|strstr:"8"}class="selected"{/if} where 8 is the ID of your CMS page... I just tried you solution, it was working well but the number for the cms page was the same with the number of a category page. And because of that when i selected the category, the cms link was on. So i edited your solution and it worked. I added to your solution: {$request_uri | strstr:"8-cmspagename"} So you must add the cms page friendly url not just the ID. 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