Форуми / Cotonti / Extensions / ClassActive

A plugin to display css class based on location

tensh
#1 22.09.2013 10:42

Hi;

I made this plugin to determine in which location the user is, and if location matches the url in navigation menu, it returns the class name "active" (or any other, can be set in settings), so that the menu item can switch colors. By now it can be achieved only by "IF" statements.

Currently it works only with URLs set to "Handy" urls (custom urls probably as well).

For nested categories, provide the Parent category in class parameters (the very first parent category in structure hierarchy) - it doesn't recognize the category depth (YET).
I hope it will work right, I made it very fast so I might not think of all alteratives.

Usage: just as you would use it with cot_url(): {PHP|classactive('module','parameters')} - e.g. {PHP|classactive('page','c=news')}.
For home page it would be {PHP|classactive('','')}.
For forums it will work only for first categories, not for subforums (by now)

Example menu link with this plugin:

<li class="{PHP|classactive('page','c=news')}"><a href="{PHP|cot_url('page', 'c=news')}">News</a></li>

Attention:
I made it to work with the plugin Slots_and_tags http://www.cotonti.com/extensions/customization-i18n/slots_n_tags - because in this plugin we cannot use IF statements and I wanted to have menu somewhere at hand.

For some reason both plugins cooperate as exected in my localhost, but fail to work on my production external server. Any help? Is it because it has memcache or something?

Link to plugin:

Classactive.zip


Відредаговано: tensh (22.09.2013 10:51, 10 років тому)
Aristei
#2 22.09.2013 15:33

Very good, thanks!

Sorry for my English
Macik
#3 23.09.2013 01:30

For some reason both plugins cooperate as exected in my localhost, but fail to work on my production external server. Any help? Is it because it has memcache or something?

Can you write on what exact links it does not work? 

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F
tensh
#4 23.09.2013 17:59

It just doesn't do anything with these tags.

cot_url() gets parsed but my global class classactive() doesn't. The code as I see in page source:

<ul class="nav">
          <li class="{PHP|classactive(,)}"><a href="http://mywebsite.com" title="Site title / site description">Strona Główna</a></li>
          <li class="{PHP|classactive(page,c=turnieje)}"><a href="turnieje/ttt-vol8">Turniej Tekken</a></li>
          <li class="{PHP|classactive(page,c=galeria)}"><a href="galeria">Galeria</a></li>
          <li class="{PHP|classactive(plug,e=contact)}"><a href="contact">Kontakt/Zapisy</a></li>
          <li class="{PHP|classactive(forums,)}"><a href="forums">Forum</a></li>
        </ul>

Here's what is in cfg.menu1 in config:

<ul class="nav">
          <li class="{PHP|classactive('','')}"><a href="{PHP.cfg.mainurl}" title="{PHP.cfg.maintitle} {PHP.cfg.separator} {PHP.cfg.subtitle}">{PHP.L.Home}</a></li>
          <li class="{PHP|classactive('page','c=turnieje')}"><a href="{PHP|cot_url('page', 'c=ttt-vol8')}">Turniej Tekken</a></li>
          <li class="{PHP|classactive('page','c=galeria')}"><a href="{PHP|cot_url('page', 'c=galeria')}">Galeria</a></li>
          <li class="{PHP|classactive('plug','e=contact')}"><a href="{PHP|cot_url('contact')}">Kontakt/Zapisy</a></li>
          <li class="{PHP|classactive('forums','')}"><a href="{PHP|cot_url('forums')}">{PHP.L.Forums}</a></li>
        </ul>

Seems like classactive doesn't get parsed or gets parsed wrong. But in my localhost it is parsed just fine!

Source from localhost:

<ul class="nav">
          <li class="active"><a href="http://site.local" title="Site title / Site desc">Strona Główna</a></li>
          <li class=""><a href="turnieje/ttt-vol8">Turnieje Tekken</a></li>
          <li class=""><a href="galeria">Galeria</a></li>
          <li class=""><a href="contact">Kontakt/Zapisy</a></li>
          <li class=""><a href="forums">Forum</a></li>
        </ul>

If I use classactive() in header.tpl in my theme, it's parsed fine, it just doesn't work with slots and tags on my production server. Something with php settings? but what? Maybe I should change plugin's priority? Or anything?

Macik
#5 23.09.2013 21:20

It can happened because order to run plugins not specified (in that case install order can be important).

Try new version from GitHub:  https://github.com/macik/cot-slots_n_tags  (I'm fixed hook order)

First uninstall both of plugins than install ones more. Do the same on production server.

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F
tensh
#6 23.09.2013 22:12

Now my plugin doesn't work at all even without slots and tags (at production server), maybe the order should be the other way round? Hmmm.
I experimented with ordering and classactive had to have bigger priority in order to work at all (even when placed in header.tpl - slots and tags' bigger priority makes it disfunctional). It still doesn't work with slots and tags as well. If the priority was other way round, then slots and tags doesn't work. 

Haven't tested on localhost but on localhost it previously worked as expected. o_O

Macik
#7 25.09.2013 17:52

Hmm…

What does it mean «does not work at all»:  What we get for  `{PHP|classactive('','')}` string in tag? Is other tpl tags parsed in menu slot?
What version of Cotonti you are use on server? 
 

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F
tensh
#8 02.10.2013 08:00

It just displays {PHP|classactive('','')} and also other tags, lang tags, etc. in text - it doesn't get parsed. I'm using the latest 9.0.14 Cotonti. :)