Jump to content

Choose template based on URL


prestatent

Recommended Posts

PS 1.6.0.8

 

Hi

 

I've created a new module using the PS documentation. All works ok. Now I want to take this further and display a different template depending on the URL input.

 

I know I can pass a key in the URL and then code for the value in the module controller to show a different template based on the key, but this means I have to show the key in the URL.

 

I can create a new URL by going to BO->Preferences->SEO & URLs and select the module from the list only once. Is there any way to select add in the same module more than once, but give it a different rewrite-url?

 

Basically, I'm trying to get away from creating the same module three times but calling a different template for each one and have a different URL.

Thanks for any help.

Link to comment
Share on other sites

Thanks for your answer but I'm unsure how this would solve my issue.

 

- I have one module

 

- my rewrite URL is setup in BO->Preferences->SEO & URLs. I've called it "segment".

 

- The three links on my homepage are:

 

www.mysite.com/segment-test1 - should show template 1

www.mysite.com/segment-test2 - should show template 2

www.mysite.com/segment-test3 - should show template 3

 

What I want to do is show in the address bar is either www.mysite.com/segment-test1 OR www.mysite.com/segment-test2 OR www.mysite.com/segment-test3 and show the correct template. As these URL's don't actually exist I would get a 404.

 

However I can only have one URL which would be www.mysite.com/segment, as this is what is setup in BO->Preferences->SEO & URLs.

 

I don't want to go down the route of modifying the .htaccess file manually since this could be overwritten if I regenerate it.

 

All I'm looking for is a tidy UR.

Edited by prestatent (see edit history)
Link to comment
Share on other sites

I believe .htaccess is the solution here.

 

Prestashop is regenerating .htaccess only between # ~~start~~ and # ~~end~~ blocks. So if you place your rules before # ~~start~~, it will stay there and will work correct.

  • Like 1
Link to comment
Share on other sites

Does anyone know how I could set this up. Can't seem to get the url working after editing the .htaccess file.

 

My module is located in www.mysite.com/modules/althome and is based on the PS documentation on how to create a module. Has anyone created a new module before and then created a rewrite in the .htaccess file?

 

The rule in my .htaccess file is:

 

RewriteRule ^testmod$ %{ENV:REWRITEBASE}module/althome/display?page=$1

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...