3

I have a split-style + New Element button for my custom element type. Thanks to this previous thread, the right-side dropdown menu is working perfectly!

Split button

My question now is, how do I get the + New Element side of it working?

I keep studying the entries templates, to see how it's done over there. But I've noticed that when you navigate between entry sources, the page URL actually changes. When navigating between my custom element sources, the page URL does not change.

How can I help the + New Element button detect what source is currently being viewed?

3

You can see how this is working by opening craft/app/resources/js/craft.js and searching for the Craft.EntryIndex class definition.

Craft.EntryIndex is an extension of Craft.BaseElementIndex, and is used to govern all Entry indexes in Craft (including Entry selection modals). We pull that off with this line of code, which you’ll find immediately after the class definition:

Craft.registerElementIndexClass('Entry', Craft.EntryIndex);

The logic governing the “New Entry” button is a little complicated, and it relies on an initial version of the button HTML already being available on the page (thanks to the craft/app/templates/entries/_edit.html template), but all the magic happens within its onSelectSource() method, including updating the URL.

| improve this answer | |
  • Very interesting... I started to go down that path, but wanted to make sure I was headed in the right direction. I'll take another crack at it with this information in mind. Thanks Brandon! :) – Lindsey D Aug 6 '15 at 17:01

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.