1
fabou78
Hilight current module in main page nav-bar
  • 2015/12/14 21:10

  • fabou78

  • Friend of XOOPS

  • Posts: 43

  • Since: 2012/6/16


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 athttp://ocaholic.ch have managed to implement this, I wonder how.

2
Bleekk
Re: Hilight current module in main page nav-bar
  • 2015/12/14 22:00

  • Bleekk

  • Theme Designer

  • Posts: 940

  • Since: 2002/12/14


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

3
fabou78
Re: Hilight current module in main page nav-bar
  • 2015/12/14 22:55

  • fabou78

  • Friend of XOOPS

  • Posts: 43

  • Since: 2012/6/16


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.

4
Bleekk
Re: Hilight current module in main page nav-bar
  • 2015/12/15 7:51

  • Bleekk

  • Theme Designer

  • Posts: 940

  • Since: 2002/12/14


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}>

5
fabou78
Re: Hilight current module in main page nav-bar
  • 2015/12/15 8:53

  • fabou78

  • Friend of XOOPS

  • Posts: 43

  • Since: 2012/6/16


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*/

6
fabou78
Re: Hilight current module in main page nav-bar
  • 2015/12/15 9:03

  • fabou78

  • Friend of XOOPS

  • Posts: 43

  • Since: 2012/6/16


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.

7
fabou78
Re: Hilight current module in main page nav-bar
  • 2015/12/21 17:17

  • fabou78

  • Friend of XOOPS

  • Posts: 43

  • Since: 2012/6/16


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...

Login

Who's Online

134 user(s) are online (86 user(s) are browsing Support Forums)


Members: 0


Guests: 134


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits