Search code examples
phpcodeigniterexpressionengine

ExpressionEngine: Single entry template


I have created a channel called credit cards. So I have created a template group called credit-cards with an index which loops through all the credit cards and output them. This aspect works fine, here is my code for the index.html file inside credit-cards.group folder:

         {exp:channel:categories category_group="1" style="linear" dynamic="no"}
                    <div class="card-list tab" id="{category_url_title}">
                        <h2 class="category-title">{category_name} Credit Cards</h2>
                        <div class="cards">
                            {exp:channel:entries channel="credit_cards" category="{category_id}" dynamic="no"}
                                <article>
                                    <h4><a href="{url_title_path='credit-cards'}">{title}</a><span class="web-exclusive">MBNA Website Exclusive</span></h4>
                                    <ul>
                                        <li class="col-img">
                                            <a href="{url_title_path='credit-cards'}"><img width="116" height="84" alt="MBNA Platinum Credit Card" src="../lib-ui/img/cards/core/core_116x84/mbna_platinum_card_116x84.png"></a>
                                        </li>
                                        <li class="col-bt">{balance_transfer_rate}</li>
                                        <li class="col-purchases">{purchases_rate}</li>
                                        <li class="col-features">{key_features}</li>
                                        <li class="col-apply">
                                            <a rel="blank" class="btn btn-success" href="{apply_url}">
                                                Apply Now<span class="hide"> for the {title}</span>
                                            </a>
                                            <a class="cta" href="{url_title_path='credit-cards'}">
                                                Learn more<span class="hide"> about the {title}</span>
                                            </a>
                                            <label class="mbna-credit-card checkbox" for="compare_1">
                                                <span tabindex="0">
                                                    <input type="checkbox" value="mbna-credit-card" id="compare_1">
                                                </span>
                                                <span class="hide"> Add the {title} to </span>Compare
                                            </label>
                                        </li>
                                    </ul>
                                    <p class="rep-ex">{representative_example}</p>
                                </article>  
                            {/exp:channel:entries} 
                        </div>
                    </div>
                {/exp:channel:categories}

So my question is this. Say I have a credit card called visa credit card, the url that is being generated for it is /credit-cards/visa-credit-card. When I click this link though I just get my index page again. I have created another template file inside my group called single.html that has the code to output a single credit card. This looks like so:

<h1>Credit Card Page</h1>
{exp:channel:entries channel="credit_cards" limit="1"}
{if no_results}
{redirect="404"}
{/if}

So how do I get it to use this template file instead for a single entry?


Solution

  • Thanks for all the great suggestions. I used the pages modules in the end which allows you to specify which template to use.