Search

Hello,

I think this is a very common scenario that came up with every site i did (two so far…).

Here is the site URL structure we’re aiming for:

home/products
home/products/aproduct

For the home/products page I want to use a DS that contains just the names of ALL the products. For the home/products/aproduct page I want to use a DS that contains all the details of just ONE product.

For either pages I don’t want the DS of the other one, it would be unnecessary and waisting CPU cycles.

To use different DS I would need to create two “Pages” items in the Blueprints section but I cannot nest one directly under the other (only two levels down, like home/products/anotherpage/aproduct ).

Thanks for any insight,

Balint

(Coninuted from the thread Empty URL handles.)

My comment in the other thread gets you half way there: you use one Data Source “Products” and filter the name by the URL Parameter {$product}. However as you say, the drawback here is that you need to include all of the product fields in the Included Elements list (to show them all on the product detail view), which is wasteful on the product list view where you just want the product names.

You can go about this in a couple of ways:

Firstly, continue to use a single DS, accept the additional data in the Data Source XML and write it off as an acceptable overhead. You could also add a layer of caching to the DS (e.g. Cacheable Data Source extension) such that it is cached for X minutes/hours.

Alternatively you could continue to use one page, but use two Data Sources, as you describe in your other thread: one for Product List, another for Product Detail. In the latter DS you can add your {$aproduct} URL Parameter to the Required URL Parameter box in the DS editor, so that when viewing the product list view the Product Detail DS doesn’t execute.

However you also want the opposite i.e. when viewing a product detail view you don’t want the Product List DS to execute. While this isn’t supported natively (yet!) you can add one line of PHP to the DS file:

Tip: Don’t execute Data Source if a URL parameter is set

This would be the easiest solution in my eyes.

The third option is, use the two afformentioned Data Sources, but attachem theme each to a separate page (rather than the same page). But, as you say, you can’t achieve the same level of clean URLs since each page requires its handle to be present in the URL. So you would end up with:

/products/
/products/detail/{product-name}/

This is acceptible in my eyes (the convention is used in this website) but I think you can get around it. Using Rob’s URL Router extension you might be able to create a regular expression rule to catch the /products/{something} URL and map it onto your /products/detail/{something} page.

Encountered this same issue myself just the other day, came up with a slightly different solution.

Similar to your third option above Nick, I created 2 x datasources and 2x pages except I set them as:

/products/all/
/products/{product-name}/

I then used the ‘Redirect to subpage’ extension to direct all requests for /products/ to /products/all/.

Unfortunately I did have to modify the redirect extension to get this to work though as it doesn’t natively take URL Parameters into account (it was initially redirecting even when attempting to view a single product page).

Since I’d rather not have to use the /all/ page I think I might switch and give the second option with Nils’ tip a go.. Thanks!

Thanks, I know what are the possibilities now…

I think all the solutions you mentioned are fine. Especially as you and Knupska said the second option is really close. In fact i spent an hour the other day trying to achieve this (turn off a DS with a parameter). So this is how you do it! :)

Problem solved! Thanks!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details