Search code examples
templatesurlexpressionengine

In ExpressionEngine 2, is it possible to use the same 'page' template for multiple pages?


Let me clarify: I am building a relatively simple brochure site that has multiple sections that I would like to use the same 'template'. For example: http://example.com/section1 & http://example.com/section2. I would also like these two sections to use the same 'view' template for their individual entry pages, for example on http://example.com/section1/item1 or http://example.com/section2/item2/.

Is this possible? I am very new to EE & have been reading about lots of ways to change url structure etc but nothing quite like what I'm asking. I am also aware that my solution could be achieved by creating two template groups with identical index templates with them but that seems rather silly.

P.S. I know my channel settings might be relevant so please let me know what they should be in order to answer this.

Many thanks

Zander


Solution

  • Yes, this is possible, and you've got a few options.

    The first is to use Structure. Structure allows you to use the same page templates across multiple pages (ie http://example.com/section1 and http://example.com/section2). This is probably your best bet.

    The second option is to use the Pages Module that comes with ExpressionEngine.

    The third option is to make your index template a simple 'router'. It would go something like this:

     {if segment_2 == 'item1'}
         {embed="template_group/template_name" entry_id="4"}
     {if:elseif segment_2 == 'item2'}
         {embed="template_group/template_name" entry_id="3"}
     {if:elseif segment_1 == 'section2'}
         {embed="template_group/template_name" entry_id="2"}
     {if:elseif segment_1 == 'section1'}
         {embed="template_group/template_name" entry_id="1"}
     {/if}
    

    This will look at the URL segments and then embed the same template for each, and pass it the entry ID which you can use in your {exp:channel:entries} tag to display the content from the appropriate entry.