Extension, Fieldtype, Module

Developer
Supported

Taxonomy

ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From iain

     

You must be logged in to post.

CSS active class when assigning only a template group and not a template

Bug Report

Todd Perkins
Todd Perkins

Hey Iain,

I came across this one.  When I want to have a navigation item go to the root template group, say for instance /blog for my blog template, with no blog -> entry assigned, it throws things off.  What was happening was that for regular “pages” the CSS class active was being added fine, but custom channels were getting the active class added all of the time. 

I am attaching a revised /library/MPTtree.php file for you to compare to yours to see the changes I made.  Might not be the best, but with limited knowledge of the rest of the system, it seems to work.

Thanks man, let me know if you have any questions,
Todd Perkins (webdezzo)

File Attachments
MPTtree.zip  (File Size: 20KB - Downloads: 117)
iain
# 1
Developer
iain

Hey Todd

Thanks for this. Haven’t had time to test what you’ve done but am I right in saying your mods now add a trailing slash to urls generated?

EE2 has pretty much removed the trailing slash on system generated urls so I’m following suit where I can.

I don’t actually let the nav tag work on auto mode much, so probably why this issue has made its way in. My setups usually always have an entry associated with a node (unless its an external link).

For example if I had the template group /about, and I wanted a node to point to /about, I would still assign an entry to that node and assign an override of /about. That way I can get the active class added by the node_entry_id parameter, and I get the added benefits of a few more css hooks generated by the tag…

It’s a beautiful day here and the surf is up, so will have a closer look at the issue when I can.

thanks again for reporting,

Iain

Todd Perkins
# 2
Todd Perkins

Hi Iain!

Yeah, the file I sent now adds the trailing slash to both node_url and viewed_url.  I definitely agree that its good to follow suit with what EE is doing, so if you can find a more elegant solution that would rock.  I think the big thing is just being able to have a navigation item that has the capability of just going to /about without an entry, and being smart enough to keep the class=‘active’ right all the way through.

For instance, in my case, we want to have a main level navigation item called “News & Events” that goes to a news_events template group.  This template will pull in both news channel entries, and event channel entries, but it’s not specific to a news entry or an event entry, its just the news and events homepage.

Enjoy the surf while you still can!

-Todd

iain
# 3
Developer
iain

Summer is only starting for us down here, lots of surf to come :)

I’ve updated where the $node_url and $viewed_url are set on my local install and this seems to work ok for me. (around 2715 of MPTtree.php)

$node_url     rtrim($this->EE->functions->remove_double_slashes($node_url), '/');
$viewed_url rtrim($this->EE->functions->remove_double_slashes($viewed_url), '/'); 

I’m just removing the trailing slash if it exists for both now.

Let me know if this is ok for you… It’s a bit of an assumption to just remove the trailing slash, especially if it’s a relative url like /about/, but the way I see it is that {path=/about/} in EE renders as domain.com/about so its not entirely unexpected…

Let me know if you think this assumption would be an issue,

cheers

Iain.

Todd Perkins
# 4
Todd Perkins

Sounds cool, I’ll add that to my version this weekend sometime and post back!  Thanks Iain!

Todd Perkins
# 5
Todd Perkins

Hey Iain,

I downloaded a fresh copy from Github, and applied your updated $node_url & $viewed_url.  It still keeps the active class on items set in the control panel that do not have an entry selected (it’s not getting an entry ID).

After looking into it more, it looks like the culprit is here:

In file MPTtree.php, around line 2666 you have:

if($data['entry_id'== $options['entry_id'])
{
     $active 
'active';

What is happening it looks like, is since there is no Entry selected, there is no entry id.  But both $data[‘entry_id’] and $options[‘entry_id’] will always be set to nothing.  Which means they will both always equal the same, and in turn always add the $active = ‘active’.  So I added this, which just also checks to make sure there is an entry id supplied, and its not just checking to see if nothing == nothing:

if($data['entry_id'== $options['entry_id'&& $data['entry_id'!= '' && $options['entry_id'!= '')
{
     $active 
'active';

This fixes everything up so that you can select just a template group in the control panel, without an entry and it still shows the correct active classes everywhere.

-Todd

iain
# 6
Developer
iain

Hey Todd,

That’s been submitted into 1.062 and you’ve been immortalised in the change log ;)

Cheers

Todd Perkins
# 7
Todd Perkins

Hey Iain!

Awesome!  Thanks man, and great work again on taxonomy!