Jump to content

If Statement Help


LittleOrbit

Recommended Posts

I created a custom navigation for my forums. I want to be able to set an 'active' class on my Members link if you are on the Members page. How would I go about doing this?

I was hoping to do something like if (on the member_page) { set the 'active' class }; I have tried with PHP, but I couldn't get this to work within the template file.

 

Link to comment
Share on other sites

core > front > global > navBar

		<ul id='ipsLayout_mainNav' class='ipsPos_left'>
			{{if !in_array('ipsLayout_minimal', \IPS\Output::i()->bodyClasses )}}
					{{$extensions = ( \IPS\Member::loggedIn()->language()->isrtl ) ? array_reverse( \IPS\Application::allExtensions( 'core', 'FrontNavigation' ) ) : \IPS\Application::allExtensions( 'core', 'FrontNavigation' );}}
					{{foreach $extensions as $id => $nav}}
					{{if $nav->canView()}}
						{{$tabId = uniqid();}}
						<li data-role='navItem'>
							<a id="elNavigation_app_{expression="strtok( $id, '_')"}_{$tabId}" href='{$nav->link()}' class='elNavigation_app_{$id}{{if $nav->active()}} ipsNavActive{{endif}}' {{if $children = $nav->children()}}data-ipsMenu data-ipsMenu-activeClass='ipsNavActive_menu'{{endif}}>
								{$nav->title()}
								{{if $children}}
									&nbsp;<i class='fa fa-caret-down'></i>
								{{endif}}
							</a>
							{{if $children}}
								<ul id="elNavigation_app_{expression="strtok( $id, '_')"}_{$tabId}_menu" class="ipsMenu ipsMenu_auto ipsHide">
									{template="navBarChildren" app="core" group="global" params="$children"}
								</ul>
							{{endif}}
						</li>
					{{endif}}
				{{endforeach}}
			{{endif}}
			<li class='ipsHide' id='elNavigationMore' data-role='navMore'>
				<a href='#' data-ipsMenu data-ipsMenu-appendTo='#elNavigationMore' id='elNavigationMore_dropdown'>{lang="more"} <i class='fa fa-caret-down'></i></a>
				<ul class='ipsHide ipsMenu ipsMenu_auto' id='elNavigationMore_dropdown_menu'></ul>
			</li>
			{{if member.group['g_view_board']}}
				<li class='ipsHide cCommunityHome'><a href='{setting="base_url"}' title='{lang="go_community_home"}'><i class='fa fa-angle-left'></i> {lang="community_home"}</a></li>
			{{endif}}
		</ul>

 

//see \core\front\global\footer
{{if \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members' ) )}}
        <li>
                <a href='{url="app=core&module=members&controller=directory" seoTemplate="staffdirectory"}' class="{{if \IPS\Dispatcher::i()->application->directory == 'core' AND \IPS\Dispatcher::i()->module->key == 'members'}}ipsNavActive{{endif}}">{lang="staff"}</a>
        </li>
{{endif}}

 

Link to comment
Share on other sites

My work around in 3.X was the following code.

<if test="applicationsloop:|:is_array($header_items['applications']) AND count($header_items['applications'])">
    <foreach loop="applications:$header_items['applications'] as $data">
        <if test="showingapp:|:$data['app_show']">
            <if test="IPSLib::getAppTitle($data['app_dir'])=='Members' AND $data['app_active']==1">
                <span class="mainNavLink_sub mainNav-community" id="mainNav-members" style="display: none;" active="true"><a class="mainNavLink_sub_highlight" title="Members" href="/members/" active="true">MEMBERS</a></span>
                <span class="mainNavLink_sub mainNav-community" id="mainNav-forums" style="display: none;" active="true"><a class="content" href="/" title="Forums">FORUMS</a></span>
            </if>
            <if test="IPSLib::getAppTitle($data['app_dir'])=='Forums' AND $data['app_active']==1">
                <span class="mainNavLink_sub mainNav-community" id="mainNav-members" style="display: none;" active="true"><a class="content" title="Members" href="/members/">MEMBERS</a></span>
                <span class="mainNavLink_sub mainNav-community" id="mainNav-forums" style="display: none;" active="true"><a class="mainNavLink_sub_highlight" href="/" title="Forums" active="true">FORUMS</a></span>
            </if>
        </if>
    </foreach>
</if>

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...