I have a single template I'm using to display a list of audio files. When the user clicks on the audio they want to listen to, it uses a conditional statement to display the single entry in the same template. I'm using:

{if segment_2 == ""} then show list of files, and paginate
{if segment_2 != ""} then show single entry

The problem occurs when you click the pagination link to go to the next page in the list and EE adds a segment 2 to the url (i.e. P2, P3, etc.). Because of that, the conditional is met, and rather than displaying the next page in the list, it displays the next single entry. I'm looking for a way around this.


I know you asked for a non third party solution but, currently, native solutions are problematic from a performance point of view, mainly due to the way native complex conditionals work in EE and because you have to deal with pagination.

My favourite solution involves using Switchee (free):

{exp:switchee variable = "{segment_2}" parse="inward"}
  {case value="#^P(\d+)$#|''|category"}
    ... list page ...

  {case default="yes"}
    ... detail page ...

There is an article dedicated to the "issue" on EEInsider


Create a new template in the same group called "view". Its another template for sure but if you don't want to add an extension your choices are limited. Breaking your "one template does all" but the cost is negligible assuming your using snippets or globals to make up your html head/footer content.


Is segment 2 the url title of the single entry? If so, could the reverse of your conditional work?

{if segment_2 == url_title}
    display just single item (likely with url title param in the entries loop)
    display list

I'm not certain if this would work, but I thought I'd mention it as a different way you could try expressing your conditional. This adds complexity to the conditional, however, and so introduces more performance weight than @jerome-coupe's suggestion, which is probably how I would handle it unless native is absolutely necessary to your situation. Switchee is a terrific way to parse the conditional more simply with case logic and it has the benefit of being able to detect pagination with regex as he mentioned.

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