Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Category & Parent IDs Rate Topic   - - - - -

 
  • bholland
  • Senior Member
  • Members
  • Join Date: 16-May 06
  • 129 posts

Posted 09 November 2007 - 07:04 AM #1

Hi All,

I'm trying to get my navigation category to stay "highlighted" when I'm in a sub category or product page. The general categories_tree.tpl has some code in it to check if the current category matches category ID:



{if $category.category_id == $smarty.get.category_id}



This is pretty basic and lets me set a class for my HTML element (which is what I want to do). I also want to be able to check if the current category and/or product id has a parent ID...How do I access this variable? In the Smarty Debug I can see this:


4 => Array (6)
  category_id => "122"
  parent_id => "85"
  id_path => "85/122"
  category => "Desktops"
  position => "0"
  level => 1


I want to have some code work that looks like this:

If current category = current category or current category parent id then do this

Anyone dealt with this before?

Thanks,

B
CS Cart 1.3.5 SP1

 
  • bholland
  • Senior Member
  • Members
  • Join Date: 16-May 06
  • 129 posts

Posted 09 November 2007 - 09:07 PM #2

Okay, I think I know what I was doing wrong...You can't access the parent_id of the current category_id...So, it looks like it might require an additional For Each loop to assign the parent_id of the current category before looping back through again.

That probably made no sense if you haven't looked at the category_tree.tpl, but thought I'd post in case anyone ran across a similar issue.

B

 {assign var="current" value=$smarty.get.category_id}
	{foreach from=$categories item=category key=cat_key name='categories'}
		{if $category.category_id == $current}
			{assign var="parent" value=$category.parent_id}
		{/if}
	{/foreach}

{foreach from=$categories item=category key=cat_key name='categories'}
	{if $category.level == "0"}
		{if $ul_subcategories == 'started'}
			</ul>
			{assign var='ul_subcategories' value=''}
		{/if}
		<ul class="menu-root-categories">
			<li style="background-color: #e7eff7;"><a href="{$index_script}?{$target_name}=categories&category_id={$category.category_id}" class="{if $category.category_id == $smarty.get.category_id || $category.category_id == $parent}subcategories-link-active{else}subcategories-link{/if}">{$category.category}</a></li>
		</ul>
	{else}
		{if $ul_subcategories != 'started'}
			<ul class="menu-subcategories">
				{assign var='ul_subcategories' value='started'}
		{/if}
		<li style="padding-left: {if $category.level == "1"}13px{elseif $category.level > "1"}{math equation='x*y+13' x='7' y=$category.level}px{/if};"><a href="{$index_script}?{$target_name}=categories&category_id={$category.category_id}" class="{if $category.category_id == $smarty.get.category_id || $category.category_id == $parent}subcategories-link-active{else}subcategories-link{/if}">{$category.category}</a></li>
	{/if}
	{if $smarty.foreach.categories.last && $ul_subcategories == 'started'}
		</ul>
	{/if}
{/foreach}

CS Cart 1.3.5 SP1