Quickie: Creating a front end Navigation Tab on IPS4

@Mikey on 16/12/2014 10:40

Creating a Front End Navigation Tab

  1. Navigate to /applications/YOURAPP/extensions/core/
  2. Create a new directory under the above directory, so we'll have a path looking like /applications/YOURAPP/extensions/core/FrontNavigation/
  3. Create a new file which has the same name as your application with the following contents:

<?php
/**
 * @brief      YourApp
 * @author          <a href='http://mikeylicio.us'>Michael Burton</a>
 * @copyright  (c) 2014 Michael Burton
 * @package         IPS Social Suite
 * @subpackage YourApp
 * @since      14 Dec 2014
 * @version         
 */
 
namespace IPS\yourapp\extensions\core\FrontNavigation;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
    header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
    exit;
}

/**
 * Front Navigation Extension: YourApp
 */
class _YourApp
{
    /**
     * Can access?
     *
     * @return    bool
     */
    public function canView()
    {
        return \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'teams', 'teams' ) );
    }

    /**
     * Get Title
     *
     * @return    string
     */
    public function title()
    {
        return \IPS\Member::loggedIn()->language()->addToStack('__app_teams');
    }
    
    /**
     * Get Link
     *
     * @return    \IPS\Http\Url
     */
    public function link()
    {
        return \IPS\Http\Url::internal( "app=teams&module=teams&controller=index", 'front', 'teams' );
    }
    
    /**
     * Is Active?
     *
     * @return    bool
     */
    public function active()
    {
        return \IPS\Dispatcher::i()->application->directory === 'teams';
    }
    
    /**
     * Children
     *
     * @return    array
     */
    public function children()
    {
        return array();
    }
}

Make sure the path is /applications/YOURAPP/extensions/core/FrontNavigation/YourApp.php

This adds a new tab to your navigation menu. For any child menus you would adjust the children() method accordingly.

Comments on “Quickie: Creating a front end Navigation Tab on IPS4”

There are no comments! :(