1

I am creating a page in my site with a list of entries under 1 channel.

I have the template structure as follows:

  • collections/ss14
  • collections/aw14
  • collections/index

The ss14/aw14 templates pull in data from the channel with all their entries listed here is my template so far:

<div id="container" class="collection">
{if segment_4 == "ss14"}
<div id="gallery-t-group" class="rsMinW">
<h1>this is the list view</h1>
   {exp:channel:entries channel="ss14" dynamic="yes" url_title="{segment_4}"}
      <div class="portfolio load-slide">
        <img data-rsh="400" class="rsImg {dimension} root" src="{images}{url}{/images}" alt="{long_name}" />
            <div class="rsTmb"><img class="{dimension}" src="{images}{url}{/images}"></div>
            <input type="hidden" value="{path={site_short_name}/collections/{channel}/{url_title}}" class="perma_link" />
    </div>
   {/exp:channel:entries}
</div>
{/if}
{if segment_4 == ''}
<div id="gallery-t-group" class="rsMinW single">
   {exp:channel:entries channel="ss14" dynamic="no"}
      <div class="portfolio load-slide">
        <img data-rsh="400" class="rsImg {dimension} root" src="{images}{url}{/images}" alt="{long_name}" />
            <div class="rsTmb"><img class="{dimension}" src="{images}{url}{/images}"></div>
            <input type="hidden" value="{path={site_short_name}/collections/{channel}/{url_title}}" class="perma_link" />
    </div>
   {/exp:channel:entries}
</div>
{/if}
<div class="rsnav-container">

</div>  
</div><!--End Content-->

Basically the idea here is that I am trying to have a list layout if its under the url /collections/ss14 or /collections/aw14 and then when you go into the single entry itself /collections/ss14/entry-title or /collections/aw14/entry-title I would ideally need to have a different layout as it needs to be using some other parameters inside the channel entries tag.

Does anyone know a good solution to this problem as I am sure there are people who run into this problem all the time when dealing with expression engine.

Cheers

2

There are a variety of approaches to this. One tool that always proves useful when trying to serve a wide range of layouts and content from a single template is Switchee. This will usually cover all the bases for you! Plus it's more efficient and flexible than native conditionals.

Other approaches to play with (either in conjunction with Switchee or separately):

Use a URL segment variable in the channel parameter on your channel:entries tag. And if the different channel's have slightly different output requirements you can couple that with a conditional based on channel_short_name. For example:

{exp:channel:entries channel="{segment_3}" dynamic="yes" url_title="{segment_4}"}
    {if channel_short_name == "ss14"}
        {!-- ss14-specific template stuff here --}
    {/if}
    {if channel_short_name == "aw14"}
        {!-- ss14-specific template stuff here --}
    {/if}
{/exp:channel:entries}

And finally, you can use simple conditionals inside channel:entries tag parameters. Sometimes this can give you an added boost to flexibility that allows you to use a single template in multiple ways. For example, on an opening channel:entries tag:

{exp:channel:entries channel="{segment_3}" 
    {if segment_4}
        dynamic="yes" url_title="{segment_4}"
    {/if}
}
{/exp:channel:entries}

(This last example is pretty hypothetical, and meant only to illustrate how simple conditionals can be used on channel:entries parameters, so please take with a grain of salt.)

I hope that helps!

8
  • Hey Alex, can the first one be used from one channel entry only because thats what i am trying to do?
    – M dunbavan
    Jan 14 '14 at 19:37
  • 1
    I'm not sure I understand, but if by "first one" you mean Switchee, then yes almost certainly. Switchee is an extremely flexible way to build conditionals.
    – Alex Kendrick
    Jan 14 '14 at 19:44
  • So like I mentioned above, I have one template that acts to show the list of the entries for that channel and the single item. Is it better to use the 2nd solution for this, the second being the 2nd piece of code and the 1st being the first piece of code?
    – M dunbavan
    Jan 14 '14 at 19:55
  • Is the list of entries paginated? If so, you will need to use Switchee (because sometimes segment_4 will hold a pagination slug, not a url_title). If you are not paginating your listing then your options open up and you can use whichever approach appeals to you.
    – Alex Kendrick
    Jan 14 '14 at 19:57
  • no its not paginated so I can use either then, I just got the aw14/ss14 channel short name bits muddled up as this is not what I am going to be switching
    – M dunbavan
    Jan 14 '14 at 20:00

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.