xoops forums

fabou78

Friend of XOOPS
Posted on: 2015/12/14 21:10
fabou78
fabou78 (Show more)
Friend of XOOPS
Posts: 43
Since: 2012/6/16
#1

Hilight current module in main page nav-bar

I am trying to implement the nav-bar so that it knows what module is on and highlight it. I figured out that the best place to start was in system_block_mainmenu.html since it seem to do it well for the “Main Menu” block.

I have notice that
<li class="<{if !$block.nothome}>active<{/if}>">
is used for Home and
<li class="<{if $module.highlight}>active<{/if}>">
is used for the other modules.

When I tried to appy this to the nav-bar (themes/xbootstrap/tpl/nav-menu.html) I didn’t quite get the results expected
<div class="navbar-collapse collapse">
        <
ul class="nav navbar-nav">
          <
li class="<{if !$block.nothome}>active<{/if}>">
            <
a href="<{$xoops_url}>">
              <
span class="glyphicon glyphicon-home"></span> <{$smarty.const.THEME_HOME}>
            </
a>
          </
li>

          <
li class="<{if $module.highlight}>active<{/if}>">
            <
a href="<{$xoops_url}>/modules/newbb">
              <
span class="glyphicon glyphicon-bullhorn"></span> <{$smarty.const.THEME_MODULE3}>
            </
a>
          </
li>
          <
li class="<{if $module.highlight}>active<{/if}>">
            <
a href="<{$xoops_url}>/modules/contact">
              <
span class="glyphicon glyphicon-phone"></span> <{$smarty.const.THEME_MODULE4}>
            </
a>
          </
li>
        </
ul>
</
div>


When I click on the forum (NewBB) all the button in the nav-bar get highlighted (including home). It is only when I clik on Home that only Home is highlighted. Any idea what is the issue?

Also I was trying to print out what value $block.nothome and $module.highlight had. nothome displays nothing while highlight displays nothing or the value 1.

The folks at http://ocaholic.ch have managed to implement this, I wonder how.

Bleekk

Theme Designer
Posted on: 2015/12/14 22:00
Bleekk
Bleekk (Show more)
Theme Designer
Posts: 934
Since: 2002/12/14
#2

Re: Hilight current module in main page nav-bar

Hi,

you can't use module.highlight like this because it comes from the array
<{foreach item=module from=$block.modules}>


I would recommend you to use mymenus module. it does excatly what you want

fabou78

Friend of XOOPS
Posted on: 2015/12/14 22:55
fabou78
fabou78 (Show more)
Friend of XOOPS
Posts: 43
Since: 2012/6/16
#3

Re: Hilight current module in main page nav-bar

I see what you mean, there is no reference of the array in my nav-bar.

I am a bit reluctant to use a module for this as I want to keep my website as simple as possible (not too many modules)

Do you think it would be feasible to implement this using regular expression on the URL?

Something like this;

if the current URL contains "{$xoops_url}>/modules/newbb" then highlight the menu newbb.

I would do this for each module in my nav-bar. I am assuming there that a module URL allways start with {$xoops_url}>/modules/ follwed by the module name.

Bleekk

Theme Designer
Posted on: 2015/12/15 7:51
Bleekk
Bleekk (Show more)
Theme Designer
Posts: 934
Since: 2002/12/14
#4

Re: Hilight current module in main page nav-bar

I would suggest you to use this module.
It is a really good module for menus and there is already a bootstrap template for menus.

You can also use smartys like
<{ if $xoops_requesturi  == "/modules/news/article.php?storyid=1"}>active<{/if}>


Or you can use
<{if $xoops_dirname == "smartfactory"}>active<{/if}>

fabou78

Friend of XOOPS
Posted on: 2015/12/15 8:53
fabou78
fabou78 (Show more)
Friend of XOOPS
Posts: 43
Since: 2012/6/16
#5

Re: Hilight current module in main page nav-bar

Thanks,

I will have a look to the module but one of the reason that I don't like modules is that you run into issues when you want to upgrade and that module is not upgraded to new version.

I understand what you are doing in your first example and I will test if it understand wilcard like this

{ if $xoops_requesturi  == "/modules/news/*"}


my aim would be to try to match anything that has /modules/news/ in it.

I don't understand your second example because don't know what "smartfactory" is but I will test it also.


Thanks again*/

fabou78

Friend of XOOPS
Posted on: 2015/12/15 9:03
fabou78
fabou78 (Show more)
Friend of XOOPS
Posts: 43
Since: 2012/6/16
#6

Re: Hilight current module in main page nav-bar

As a side note the "*/" after "Thanks again" above has been added by XOOPS and I can't seem to be able to get rid of it.

fabou78

Friend of XOOPS
Posted on: 2015/12/21 17:17
fabou78
fabou78 (Show more)
Friend of XOOPS
Posts: 43
Since: 2012/6/16
#7

Re: Hilight current module in main page nav-bar

Following Bleekk lead and some search on internet I came to use php fuction strripos as follow

{if (!strripos($xoops_requesturi, '/modules/newbb') === false)}>active<{/if}

Seem to be doing the job fine...