2

I have a small menu of fixed entries that forms a sub-nav on a site.

I'm currently using Reference Tag parsing to grab links to these entries:

<li><a href="{{ '{entry:3666:url}' | parseRefs }}">Help</a></li>
<li><a href="{{ '{entry:3667:url}' | parseRefs }}">Donate</a></li>
<li><a href="{{ '{entry:3668:url}' | parseRefs }}">About Us</a></li>

I think this is a really clean/readable way to create this sub-nav, but I'm not sure about the performance implications. I could accomplish the same thing by calling up an ElementCriteriaModel using a fixedOrder:

{% entries = craft.entries.id(3666, 3667, 3668).fixedOrder(true) %}
{% for entry in entries %}
    <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
{% endfor %}

Does anybody know if one option is significantly performant over the other?

(I wouldn't be surprised if Craft is intelligently caching its entry data queries, such that it wouldn't have to create a new element query each time a Reference Tag is encountered/parsed... but I'm not knowledgable enough to say.)

Other SE questions about best-practice for linking to single entries:

1

If you turn on debug mode in your config file, and then create an ultra simple template with just these code options in it, you should be able to look at the logs in the console. It should tell you the query time in milliseconds. I've never used reference tags; however, I would suspect that the performance difference is minimal. I personally would opt for the second method, so that entry.title is not hard coded.

As a side note, you can also wrap the code in {% cache %}... {% endcache %} tags to further increase performance either way.

  • If you needed the titles to be dynamic, you could parse {entry:3666:title} as well. Thanks for the debugger idea. – Michael Rog Feb 2 '15 at 2:22

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.