0

I'm trying to figure out a way to display each entry in a channel on one page but allow for those entries to utilize different templates. The templates would be various layouts for a section and each section would be an entry.

I'm currently using the pages module so I can select a different template but I want to display it on the home page. Each template is just a variation of the next with rows and columns for content. I'm basically trying to make the home page modular.

====== MORE DETAIL =======

At this point it's done in the back end. My goal is to eventually move it to the front end but for now I just need to get it working.

The home page has a layout for the header, nav, call-to-action row, and footer that will stay consistent on the home page. The user has some layout options to choose from globally but the area I need to address is the entries that will appear on the home page through the "home" channel.

I want to create various layout options for the content row and each entry would display a new row of content. No different how a news channel would work other than the option to choose a different row layout for the entry.

I would like the user to go in and create a new "home" entry from the content menu and select the template they want to use for that specific entry in the pages module template dropdown. It could one column or two, whichever fits their need.

If the client created a new entry with a one column template then it will appear on the home page in the designated content area for the "home" channel entries. Every entry would be a new row based on the template selected. Again, we are talking about if the row will have 1, 2, or three columns and the width of those columns that are defined in the template.

Does this help?

I would think it would be as easy as displaying the entry but selecting a different template outside of the index seems to be throwing it off.

  • Why not just use the exp:channel:entries tag with a dynamic no parameter? That will loop thru all of your channels – Mark Busnelli Jr Sep 9 '15 at 4:21
  • That was my original thought but when I created a page/entry it would not pull in all templates, just the one in the index page. – lanceb Sep 9 '15 at 14:16
0

So let me get this straight... You want to load different templates based on user choices? So the homepage could be template1 or template2 depending on a condition? Weird.. But ok. Have you considered just embedding template parts?

{if condition_a}
    {embed="embeds/template_a"}
{if:else}
    {embed="embeds/template_b"}
{/if}

If you could expand on the purpose of subjectively loading different templates, I can hone my answer in.

| improve this answer | |
  • No exactly. The entire layout will not change, only the entry area. It's a simple change in layout based on the clients need. It is simple as using a template that has a row with 2 columns, 1 column, etc. If I put all the layouts in one file with conditionals then I won't be able to allow the user to see the thumbnails based on the layout using Better Pages. – lanceb Sep 9 '15 at 14:17
  • I need you to expand on what conditions will trigger different layouts. Is it front end (like, the client can click "Switch to single column")? Backend (the user sets a settings in their profile to display as "Two column")? Please edit your question and fill in some details to I can figure out the best way to help you. – jrothafer Sep 9 '15 at 14:21
0

You could put a field in the home channel entries with the layout options. Then code your page so that it displays differently based on the layout option that was selected.

| improve this answer | |
  • That may end up being the answer but I'm hoping to be able to utilize the pages module so I can integrate Better Pages with it for the use of the thumbnails. – lanceb Sep 10 '15 at 2:41
0

Try this. Within your exp:channel:entries loop on your homepage template that you are using to display the homepage entries. Output the custom field you have setup for better pages.

{exp:channel:entries channel="homepage" dynamic="no"}
  <h2>This is the template id {my_better_pages_field}</h2>
{/exp:channel:entries}

If my understanding of better pages is correct this is the id for the template you have assigned to that entry. Now using this information you can create your conditionals on your homepage template for example

{exp:channel:entries channel="homepage" dynamic="no"}
  {if {my_better_pages_field} == "1"}
    Enter output of the first style
  {/if}
  etc etc.
{/exp:channel:entries}

Normally when you assign a template to a page using the pages module it displays the page using the corresponding template when you call up that pages url. You are wanting it to use the template while displaying a different page. If you actually want to use the templates you have assigned you could use the above code with an embed. for example replace "Enter output of first style" with {embed="template_1" passedid="{entry_id}"} and then use the {embed:passedid} variable within your template. Hope that works for you.

| improve this answer | |
  • Thanks for the reply, Phil. I'll give it a try. Sounds like it should work. I'll update the status as soon as possible. – lanceb Sep 16 '15 at 23:24

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.