GithubHelp home page GithubHelp logo

cakephp-menulink's Introduction

MenuLink plugin for CakePHP 3

This is a handy and really simple plugin for displaying the active menu item based on the url. If you have a link pointing to the current url, it will get an "active" css class. You should add your own css definitin for a.active to your css file.

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require rrd108/cakephp-menulink

Usage

Load the plugin

Load the plugin in your /config/bootstrap.php file

Plugin::load('MenuLink');

Load and use the helper

You can load the helper in two different ways, the reccomended way or the override way.

Recommended way

In your /src/View/AppView.php file at your initialize() method load the helper like this.

$this->loadHelper('MenuLink.MenuLink');

In this case in your view files you should use the helper like this.

$this->MenuLink->menuLink(
    'Link text',
    [
        'controller' => 'posts', 
        'action' => 'index'
    ],
    [$options]
);

The menuLink call handles the same paramaeters as the core Html helper's link method

Override the Html helper

This is a little bit more comfortable way to do the same above. As this way overrides the core Html helper it can conflict with other helpers trying to override the same thing.

In your /src/View/AppView.php file at your initialize() method load the helper like this.

$this->loadHelper('Html', ['className' => 'MenuLink.MenuLink']);

In this case in your view files you should use the helper like this.

$this->Html->menuLink(
    'Link text',
    [
        'controller' => 'posts', 
        'action' => 'index'
    ],
    [$options]
);

The menuLink call handles the same paramaeters as the core Html helper's link method

In both ways your active link will look like this, but others will do not have this css class definition.

<a href="/posts/index" class="active">Link text</a>

cakephp-menulink's People

Contributors

rrd108 avatar

Watchers

James Cloos avatar  avatar

cakephp-menulink's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.