I've developed a custom menus plugin which has been working great


Im trying to get it work with the build in template caching and realizing the reorder actions are not triggering the caches to clear properly?

The template is using the "getNodes(menuHandle)" variable https://github.com/familiar-studio/craft-menus/blob/master/menus/variables/MenusVariable.php

which just uses standard element criteria? We are also using native structures so is there some way to specifically tell it to clear on reordering as well?

UPDATE: here is the code thats in my _layout that im hoping will clear when i reorder or add new elements

{% cache %}
  <ul class="nav navbar-nav navbar-right">
      {% nav node in craft.menus.getNodes('utilityMenu') %}
         <li class="{{ node.children|length ? 'dropdown' }}
            {{ node.active ? 'active' }}">

            <a href="{{node.link}}"
                {% if node.children|length %}
                   class="dropdown-toggle" data-toggle="dropdown"
                {% endif %}>

                {{ node.title }}

            {% ifchildren %}

                <ul class="dropdown-menu" role="menu">
                    <div class="arrow"></div>
                    {% children %}

            {% endifchildren %}
     {% endnav %}

{% endcache %}

UPDATE 2: So on deeper investivation it appears that the issue is only that it doesnt clear the cache when the structure is reordered, editing and saving nodes seems to clear it after all.

3 Answers 3


So i found an answer, was a little more manual but it works.

I added a call back to the onMoveElement to automatically more manually clear the cache. This was added to my plugins init() function

craft()->structures->onMoveElement = function(Event $event) {
      $element = $event->params['element'];

Was interesting to me that i only had to do this for reordering sturctures while adding/deleting elements automatically cleared the cache with no event code.

Not sure if this was a bug or by design?


It sounds like you're trying to use the cache tag for your plugin's template files from inside the control panel.

If that's the case, don't. :)

The {% cache %} tag was designed purely to be used for front-end site templates. You'll run into all sorts of weirdness using it from templates in the control panel.

  • No no this is for front end templates. I'm outputting the menu onto the site Dec 21, 2014 at 1:06
  • Ahh, can you update the questions with some relevant example template code?
    – Brad Bell
    Dec 21, 2014 at 1:08
  • Sure, should have included that to begin with Dec 21, 2014 at 1:08
  • hmm so it might be clearing itself after all...hmm Dec 21, 2014 at 1:37
  • so adding new nodes seems to clear it actually but reordering doesnt? Dec 21, 2014 at 1:39

You could also use the cache tag in combination with a dynamic key, like the specific ordering as a key. It will however create stale cache entries, so be sure to use this only if it won't be a problem, i.e. rarely updates and/or cache cleared regularly. For custom elements reordering the given on-move approach seems better, but this method could perhaps be of use for the standard entries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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