# keystone-menus

> A Node.js module for making menus and menu items in Keystone Object-Oriented

Latest version **1.0.1** (published 2015-12-30) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install keystone-menus
pnpm add keystone-menus
yarn add keystone-menus
bun add keystone-menus
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2015-12-30 |
| First published | 2015-12-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| Author | Chas Mrozek |
| Maintainers | lcm |
| Keywords | keystone, menu, menus, nav, navigation, navbar |

## Links

- npm: https://www.npmjs.com/package/keystone-menus
- Repository: github.com:lighthousecatholicmedia/keystone-menus
- Homepage: https://github.com/lighthousecatholicmedia/keystone-menus#readme
- Issues: https://github.com/lighthousecatholicmedia/keystone-menus/issues
- npm.io page: https://npm.io/package/keystone-menus

## Dependencies (3)

- [jade](https://npm.io/package/jade.md) ^1.11.0
- [lodash](https://npm.io/package/lodash.md) ^3.10.1
- [bluebird](https://npm.io/package/bluebird.md) ^3.0.6

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2015-12-30
- 1.0.0 — 2015-12-30

## README

# Keystone Menus


## Installation

To install, simply add keystone-menus to the list of dependencies in your Keystone application's package.json and run npm install.


## Usage

**1.** In your application's keystone.js file, include the module, import its models, and add the models to your Keystone admin UI:

```js
// Simulate config options from your production environment by
// customising the .env file in your project's root folder.
require('dotenv').load();

// Require keystone
var keystone = require('keystone');
var KeystoneMenus = require('keystone-menus');

// etc...

keystone.import('models');
KeystoneMenus.import(keystone);

// etc...

keystone.set('nav', {
	// Your application's models that are loaded into the admin UI would be here.
	'menus': ['menus', 'menu-items']
});

keystone.start();
```

**2.** Start up your application and add the menus and menu items that you will be using in the admin UI. Reference the [Objects](#objects) section for details on the Menu and MenuItem objects and their fields.

**3.** In your routes (most likely in middleware.js, unless the menus only need to load on certain pages) initialize the MenuBuilder object, then use it to build a menu. Once the menu is built, render it.

```js
var KeystoneMenus = require('keystone-menus');

exports.initLocals = function(req, res, next) {

	var locals = res.locals;
	var builder = KeystoneMenus.builder();

	builder.build('navLinks')
		.then(function(menu){
			locals.navLinks = menu.render(req.path, {'class': 'nav navbar-left visible-md-block visible-lg-block'}, {}, {});
		});

	builder.build('subNavLinks')
		.then(function(menu){
			locals.subNavLinks = menu.render(req.path, {'class': ' nav navbar-right visible-md-block visible-lg-block'}, {}, {});
		});
	// etc.
};
```

The render function has 4 parameters:
* **path** The current request path. Used for setting the active li
* **ulAttributes** HTML attributes to apply to the menu's ul, example: {'class': 'nav navbar-left'}
* **liAttributes** HTML attributes to apply to the menu's lis, example: {'class': 'nav-item'}
* **aAttributes** HTML attributes to apply to the menu's as, example: {'class': 'nav-link'}

**4.** Reference your rendered menu templates in your views.

```jade
.navbar-links
  != navLinks
```

## Objects

#### Menu
* **Name:** The name you will use in your application
* **Slug:** Auto-generated by Name
* **Items:** The menu items that should be displayed in this menu

#### MenuItem
* **Name:** The name of the menu item. This is what will be displayed in the menu.
* **Href:** The path that the menu item will link to.
* **Active:** Whether this menu item will be shown in the menu.

---
_Source: https://npm.io/package/keystone-menus · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
