3

Is it possible to add another link to admin navigation? For example I have plugin clients which has it's own Button in the admin menu, in the same plugin i have newsletter so I would like to have that Newsletter in that menu as well.

6

The top links in the CP header are often called nav tabs.

Beyond the "default" nav tab for your plugin (pointing to the plugin's CP section), it's possible to declare additional tabs via the modifyCpNav hook (added in Craft 2.3.2640):

public function modifyCpNav(&$nav)
{
    $nav['mypluginhandle-newsletter'] = array('label' => 'Newsletter', 'url' => 'mypluginhandle/newsletter');
}

Of course, this will only create a tab with a link pointing to whatever you put in the url property. If you haven't already created the page for the newsletter, you'll need to do so by creating a route to a template or controller:

public function registerCpRoutes()
{
    return array(
        'mypluginhandle/newsletter' => 'myPluginHandle/newsletter',
    );
}

Read more about the registerCpRoutes hook in the official docs.

Both the modifyCpNav() and registerCpRoutes() methods should go in your plugin's main class.

1
  • Well, you learn something new everyday! Jun 3 '15 at 19:40
3

Do you mean have multiple tabbed content within your plugin admin area? If so yes that's possible you just need to add a tabs array in your template like so:

{% set tabs = {
 tab1: { label: "Tab 1"|t, url: url('plugin') },
 tab2: { label: "Tab 2"|t, url: url('plugin/tab2') },
} %}

Then to make a tab active in the navigation you would just add this to the relevant template:

{% set selectedTab = 'tab2' %}

If you are referring to having both clients and newsletter in the top navigation I don't think so, I think it's one section per plugin (but I could be mistaken)

Edit

Sorry I should have elaborated, you will also need to register additional pages in your main plugin class, like so:

public function registerCpRoutes()
{
  return array(
    'pluginHandle/some-page' => 'pluginHandle/_someTemplate'
  );
}

There is a bunch of info about this in the plugin docs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.