I was wondering how to properly call information from a channel but outside of the loop, so it doesn't repeat along with the entries. The output would look something like this:

<div id="entries" class="row">
  <div class="module">Entry 1</div> // These modules go inside loop
  <div class="module">Entry 2</div>
  <div class="module">Entry 3</div>
<div id="meta" class="row">
  <div class="aside">Content Related to channel</div> // Outside of loop

In the ee template I want to wrap all that in a single {exp} tag. I feel like that would be more efficient, in terms of code and server resources. Is that the right approach? If so how do I make the #meta element not repeat with the loop?

Or is the correct approach to have 2 {exp} sections, one for the loop and one for the other part, and wouldn't this be inefficient at some point?

Thanks in advance!

  • Is the content of the meta block coming from a relationship that depends on data coming from within the entries loop? Or is it a "static" relationship? – Jean St-Amand Aug 21 '13 at 13:42

The EE way is to do multiple exp:channel tags and pull out the relevant info. It's no big thing if you're site has average hits per day or you're not querying 1000 items.

The 'new' way involves Stash which you basically set a series of variables to the fields you want to record in one pass of exp:channel tags then output those variables wherever you like but this question indicates you're fairly new to EE so best get familiar with the way EE works and move on to some more advanced functionality once your familiar with it.

  • This is good advice for when you need to pull a variety of things out, or otherwise have a more complicated relationship between EE tags and page markup / code, etc. But, when you need to just add a block once at the top or bottom, you can use the {if count==...} {/if} approach in divtagged answer. – Jay F Aug 21 '13 at 18:15
  • Thanks for the explanation, I had tried that before and didn't work, I tried again and it did. Not sure what happened. This way always felt very "hacky" to me, I was hoping there'd be a better native way of doing it. I've been playing with Stash but as you said it, I'm just getting started so I'm barely beginning to understand it. Thanks for the extra details, it really helped! – cballenar Aug 21 '13 at 18:59
  • Despite my answer (for the "quickfix") I'd also have to agree with this advice, we use Stash and it's inherently baked into our templates and workflow. – Dave O'Brien Aug 22 '13 at 13:35
  • Yea, I was able to get it working with the counts method but I definitely wanna get more into Stash. Thanks all for the help! – cballenar Aug 22 '13 at 16:56

You could wrap the meta data inside a conditional matching the count of 1 like so:


  <div class="module">{title}</div>

  {if count == "1"}
  <div id="meta" class="row">
    <div class="aside">Content Related to channel</div> // Outside of loop


Does that help?

  • And, you can do {if count==total_results} ...{/if} when you want a block to appear only once, at the end of the loop. – Jay F Aug 21 '13 at 18:15
  • I had tried that before but didn't work, I must've done something incorrectly. If I understand correctly, this puts the code wrapped by "count==1" in front of the first item or "count 1". And total_results after the last one, meaning the last or total count. Right? – cballenar Aug 21 '13 at 18:55
  • That's correct - is your {exp:channel:entries} pair nested inside another {exp:channel:entries} pair? When debugging EE issues I'll remove everything except the code I'm debugging. Try adding the variable {count} within the pair and see what it outputs – Dave O'Brien Aug 22 '13 at 13:32

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.