1

I am wanting to get rid of template group names in the URL and basicly get more control over the URL structure.

Maybe template routes will now allow me to do what I want but not sure I understand how that works.

Example:

myhotel.com/template_group/template/entry

myhotel.com/room_types/room/double_king

where Double King is the entry title

I want: myhotel.com/room/double_king or even myhotel.com/double_king

Can I do that with template routes?

THANKS!

greg

2

I'm not sure if template routes would work as I've not had chance to use them yet, but you could achieve it without Structure by using some basic routing in your template (which may be effectively the same as the new template routing functionality).

Basically, you could change your template group to room. Then you could run a conditional on {segment_2} in the index template.

{if segment_2}
    {embed="rooms/_room_types"}
{if:else}
    {embed="rooms/_default"}
{/if}

This approach would work, but isn't ideal because of the way embeds and conditionals are parsed in EE - you'd be adding overhead to the server because it would read through both conditions, parsing both your embedded templates before deciding which one it doesn't want.

You could improve the performance by using IfElse which parses the conditionals differently, and avoid using the embedded templates, instead including your channel entries tags within the index template.

| improve this answer | |
  • 1
    Just wanted to correct that it would not parse both of your embedded templates. If it were module tags, it would, but templates are all parsed separately, and only after the parent's parsing is complete. That makes the above pattern a good choice when you need completely different tags based on certain conditions, as it will only parse the one on the child template that passes the conditional. – Derek Jones May 1 '14 at 21:59
  • Ah I see - that's great - thanks for the clarification :-) – Andrew Armitage May 1 '14 at 22:37
2

Yes, Template Routes should be able to accommodate. Given a route rule to your room_types/room template of:

/room/{room:alpha_dash}

then http://example.com/room/double_king would go to that template, and populate the {segment:room} variable with "double_king".

If you want to go to single segments:

/{room:alpha_dash}

Though the trick here is if you have other valid first segments that need to go elsewhere. You would set your routes in the order of most specific to least specific, so that if you wanted http://example.com/book-it to go to another template, you'd want to create a route rule of /book-it in a higher position.

| improve this answer | |
1

You might want to look at Structure - http://buildwithstructure.com/

It bypasses the template/group template URL structure and allows you to create any URL you like. Also makes managing a big page tree with many levels very easy, and help generate navigation and breadcrumbs too.

| improve this answer | |
  • Why would someone downvote this answer? – Benek Lisefski Apr 27 '14 at 4:59
  • 1
    Seems a sensible enough answer to me but I guess it doesn't actually answer the question which was 'can it be done with template routes'. – Andrew Armitage Apr 28 '14 at 21:03

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.