spotonlive/sl-navigation

View on GitHub
docs/02. Containers.md

Summary

Maintainability
Test Coverage
# Containers
Containers represents your navigations. Examples:
- admin.navigation
- client.navigation
- shop.menu

## Setup containers/navigations
Containers are configured in your configuration file

`app/navigation.php`
```php
<?php

return [
    'containers' => [
        'admin.navigation' => [
            'options' => [
                'ul_class' => 'nav',
            ],

            'pages' => [
                [
                    'options' => [
                        'label' => 'Home',

                        // Use your route names from laravel
                        'route' => 'admin.home',

                        // Optional route parameters
                        'route_parameters' => [
                            'language' => 'dk',
                        ],

                        // ... or specify a uri
                        'url' => '/admin/messages',
                    ],

                    // Define attributes for the <li>
                    'li_attributes' => [
                        'data-attr' => 'val',
                    ]
                ],
                [
                    'options' => [
                        'label' => '<span class="fa fa-envelope"></span> Messages',

                        // Specify if the label html needs to be escaped (default = true)
                        'escape_html' => false,
                    ],
                ],
            ]
        ]
    ]
];
```

## Sub menu's
To create sub menus simply just use the key `pages`.

`app/navigation.php`
```php
<?php

return [
    'containers' => [
        'admin.navigation' => [
            'options' => [
                'ul_class' => 'nav',
            ],

            'pages' => [
                [
                    'options' => [
                        'label' => 'Messages',

                        // Use your route names from laravel
                        'route => 'admin.messages',

                        // Set the class for the sub menu <ul>
                        'ul_class' => 'dropdown',
                    ],

                    // Set attributes for the sub menu <ul>
                    'ul_attributes' => [
                        'data-dropdown' => 'true',
                    ],

                    'pages' => [
                        [
                            'options' => [
                                'label' => 'Compose',

                                'route => 'admin.messages.compose',

                                'route_parameters' => [
                                    'subject' => 'New message',
                                ],
                            ],
                        ],
                        [
                            'options' => [
                                'label' => 'Inbox',
                                'route => 'admin.messages.inbox',
                            ],
                        ],
                        [
                            'options' => [
                                'label' => 'Sent',
                                'route => 'admin.messages.sent',
                            ],

                            'pages' => [
                                [
                                    'options' => [
                                        'label' => 'Today',
                                        'route => 'admin.messages.sent.today',
                                    ],
                                ],
                                [
                                    'options' => [
                                        'label' => 'This month',
                                        'route => 'admin.messages.sent.month',
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ]
        ]
    ]
];
```

## Custom wrappers
This option allows you to have custom wrappers for your <a>-tag.


`app/navigation.php`
```php
<?php

return [
    'containers' => [
        'admin.navigation' => [
            'options' => [
                'ul_class' => 'nav navbar-nav',
            ],

            'pages' => [
                [
                    'options' => [
                        'label' => 'Register',
                        'route' => 'user.register',
                        'escape_html' => false,
                        'wrapper' => '<div class="navbar-btn">%s</div>',
                    ],
                    'a_attributes' => [
                        'class' => 'btn btn-primary',
                    ],
                ],
            ]
        ]
    ]
];
```

* Go back to [**Getting started**](01. Getting Started.md)
* Continue to [**Providers**](03. Providers.md)