2

I'm trying to customise the elementindex view. For example I want to filter out some entries that don't match certain criteria. Also if possible add some hooks to the read calls. Is there any documentation available about this?

Thanks in advance

3

Your best bet on learning element type templating is to look at Craft template itself. Element types use the following template for controlling the layout:

craft/app/templates/_layouts/elementindex.html

However, its important to know that you should only be using the elementindexif you are creating a custom element type.

As far as the element index, a good portion of the options are actually set through Javascript by Craft using Garnish. If you look at the following code, you can see that the status, template side, is set via Garnish.

{% block initJs %}
Craft.createElementIndex('{{ elementTypeClass }}', $('#main'), {
    context:        '{{ context }}',
    showStatusMenu: {{ showStatusMenu is defined ? showStatusMenu|json_encode|raw : "'auto'" }},
    showLocaleMenu: {{ showLocaleMenu is defined ? showLocaleMenu|json_encode|raw : "'auto'" }},
    storageKey:     'elementindex.{{ elementTypeClass }}',
    criteria:       { localeEnabled: null }
});
{% endblock %}

You can set custom statuses on your element type, if that is the route you are looking to travel. I have dug into element types and custom statuses on these posts:

  1. How to integrate custom statuses in a workflow style custom element type?
  2. Best way to use custom enums in my plugin templates?
  3. Best way to implement my own statuses on my custom element type?

As for Craft documentation, they are working on it still and the only thing available right now is this:

Creating new Element Types

3
  • can you please explain: "However, its important to know that you should only be using the elementindexif you are creating a custom element type."? I'm basically trying to load an entries list inside one of my plugins' tabs
    – pythic
    Jul 27 '14 at 21:24
  • Sure thing, the elementindex is used specifically for returning elements (Entries, Users, Assets and etc.). Therefore in the beginning of the template it expects you to declare elementTypeClass. So if you are not using a custom element type, there is a little extra work as a lot of these options are set on your elementtypes/PluginNameElementType.php. Jul 27 '14 at 21:57
  • Seeing as this is over 5 years old and I assume for Craft2, does anyone know if this has changed and if there is documentation? Feb 5 '20 at 13:55

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.