Search code examples
templatesexpressionengine

ExpressionEngine content template


i have created channel called "news" and the channel field.

i have created template group called "news".

in news template group, there are "index" and "single" template.

what i want to do is when user go to url mydomain.com/news, it will show all the news with template from "index" template,

but if user go/ click to url mydomain.com/news/first-post, it will show the post with template from "single" template.

how can i achieve this? i have tried to choose "single" template from "page" tab when i publish new content, but it didn't work. the content url still show the "index" template

thanks.


Solution

  • URL routing in ExpressionEngine is as follows:

    http://www.yourdomain.com/template-group/template/entry-url-title

    It makes sense from an EE perspective that the news template is being shown when you go to mydomain.com/news/first-post. EE is looking for a template called first-post in the news template group. You can fix this in one of two ways:

    1) Change the url you're looking for to mydomain.com/news/single/first-post. This should show your post.

    2) If you don't want to show "single" in the URL, setup a condition in the main news template as follows:

    {if segment_2}
    {embed="news/single"}
    {if:else}
    ... rest of your template code
    {/if}
    

    To keep this template cleaner, you might even want to create a news/main template so you can

    {if segment_2}
    {embed="news/single"}
    {if:else}
    {embed="news/main"}
    {/if}
    

    Up to you.