2

RE: How to display Channel entry page?

The accepted solution doesn't seem to work for me. My "products/index" template has something like this:

{exp:channel:entries channel="products" limit="10" orderby="date" sort="desc"}
   <a href=/products/detail/{url_title}">{name}</a>
{/exp:channel:entries}

Then in "products/detail" template, I have something like this:

{exp:channel:entries channel="products" limit="1"}
   <h2>{name}</h2>
   <p>{description}</p>
{/exp:channel:entries}

The "products/detail" page always shows the same record (and when you look at the tag pair, it make sense I think). How is this template supposed to know which record specifically to access? What is it about {url_title} that hints to which entry to retrieve? Is there something I need to put in the tag pair to tell it to use the {url_title} segment?

2
  • When ExpressionEngine is set-up in dynamic mode, segment_3 triggers the look-up of the entry_id, title, and other parameters. If the title or entry_id is not provided in segment_3, then turn dynamic-off, and trigger the look-up based on either {url_title} or {entry_id} in the {exp:channel:entries} tag, such as {exp:channel:entries channel="products" url_title="{segment_4}" dynamic="off" limit="1"} where segment would be whichever segment you are using, 2, 4, etc. Also, test with the {title} field it will provide a better idea of what's being pulled, if anything. Dec 29, 2012 at 18:13
  • Just wanted to clarify that the last {segment} will trigger the lookup (not just {segment_3}). If it's an integer, then EE looks up by entry_id. If it's a string, it looks up by entry_url. Apr 17, 2014 at 23:13

3 Answers 3

5

Your code is correct, and should work. EE will always look at the third segment for either an entry_id or url_title, unless you specifically add dynamic="no" to your Channel Entries tag. So although the suggestions that you specify entry_id="{segment_3}" or url_title="{segment_3}" will work, they should not be necessary.

Note that in your first code sample, you should use {permalink="products/detail"} or {title_permalink="products/detail"} - more future-proof.

1
  • dynamic="no" was not included, so I'm not sure why it wasn't looking at segment_3. Yes, I'm actually using {permalink="products/detail"}. Dec 29, 2012 at 18:16
2

You could add url_title="{segment_3}" to the channel entries tag in the products/detail template.

1
  • And dynamic="no" ad I would normally use and as above points out.
    – Mark
    Dec 29, 2012 at 18:01
1

On your details template, you can add two parameters to the entries loop that should solve this - add dynamic="no" and url_title="{segment_3}".

2
  • There are other options than url_title. Say I use entry_id, do I then just add entry_id="{segment_3}"? I'm actually using permalink for testing. Dec 29, 2012 at 17:51
  • Using permalink in the products/index template. products/details seems to work when I use entry_id="{segment_3}". permalink="{segment_3}" did not work. Are these correct? Dec 29, 2012 at 18:01

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.