1

I want to have an URL which calls a View, for instance:

www.example.com/products

This will be the URL for a View called products_list

If I want to filter the products by category, I could clone the View page, add a Contextual filter based on Taxonomy, and with a URL indicated as /products/% I could use

www.example.com/products/Brand-1

to filter the products of brand "Brand 1".

But what if I want to use a completely different View, with a layout different from the above, for just the special case of some brands, i. e.,

www.example.com/products/Special-Brand

I want the above URL to use a completely different View. How can I manage to do that in the simplest possible way?

  • I do not know whether this answer will be helpful or not in this case, but yesterday I asked same kind of question, to combine 5 - 10 views using pager. I am attaching the link of my that question, you can read and if you get idea from that, just for try. Here he told me to add another view using add-page from view (drupal.stackexchange.com/questions/191633/…).. – CodeNext Feb 17 '16 at 20:36
  • Thanks for the link. I was unable to understand why to use different views for that case. Not what I am looking for, in any case. The problem lies with completely different views and same basic URL, with different set of parameters, the solution must lie in the discrimination of parameters by Drupal with some extra module, some configuration or some hook code. The hook code is what I am using, with views_embed_view, but I look for a straighforward answer. – Cesar Feb 18 '16 at 7:14
1

Exactly, that is the point. I need just 2 Views, which one shows some completely different data than the other, and for different kind of brands. But all of these brands can be grouped in 2 big groups. Now I solve it by using views_embed_view in template.tpl.php, and using a View or other in the function via database logics, but I was not sure if there was an ideal way of doing without "hard code", via Rules, Context or something.

Here is an alternative.

Create taxonomy terms.

go to /admin/structure/taxonomy

  • Add Vocabulary, call it Products
  • Then click on list terms (/admin/structure/taxonomy/products) and add terms
    • Brand A with url alias /products/brandA
    • Brand B with url alias /products/brandB

Then on your actual products content type (lets pretend it's Articles) add a term reference field of Bundle Type: Products.

Then edit your Article and select A or B for that node.

Create 2 block views (one for each type)

  • under advance, add relationship of terms on node

enter image description here

  • Then Add a contextual filter of Taxonomy Term Name

    • Provide Default Value
      • Fixed Value
        • Brand A

enter image description here

Then go to blocks, and find your 2 view blocks and configure them.

enter image description here

I only showed A here, repeat steps for B.

  • Thank you very much, very detailed answer. Now I see it. – Cesar Feb 18 '16 at 10:39
  • The only problem I see is that the URL /products/brandA also displays the list of products belonging to that taxonomy, so I get a kind of "duplication" of content. A solution could be to create the URL with hook_menu and somehow override the taxonomy listing. I will research into that. Thanks again!! – Cesar Feb 18 '16 at 10:46
  • OR you could create 2 nodes of content type Article and use URL alias of /products/brandA & /products/brandB instead of using the taxonomy term page. (change the urls of term page). – No Sssweat Feb 18 '16 at 11:08
  • 1
    Well, spirit is similar to my approach. It can be done entirely in Drupal UI (thanks again) w/o a single line of code. But my site data comes from huge database, and site is multi-(domain/language) with thousands of products, it can be a real nightmare to administer all of that using a Drupal-UI-only approach. At the very end, the hard code solution is not far from this spirit, though I use contextual relationship with no fixed value, I set that value in the views_embed_view and the part of deciding which view to use is similar to the "block filtering" that you used. Very interesting indeed. – Cesar Feb 18 '16 at 11:21
  • 1
    Ok, but the discussion has been very very valuable. Thanks. – Cesar Feb 18 '16 at 12:07
0

You add a new view by clicking Add Page

enter image description here

This will clone your original view. Then click on fields and at the top select this page override as you don't want to affect all views.

enter image description here

Then click the remove button, to remove the fields.

Do this for everything, so you can remove everything and start from scratch.

  • The problem lies in the parameters. I have two views. I need one to show for a given kind of parameters, and the other view with the other set of parameters. All for same basic URL. Don't think it is quite trivial. – Cesar Feb 18 '16 at 7:11
  • @Cesar define parameters because I am not getting it. – No Sssweat Feb 18 '16 at 7:23
  • Well, URL parameters. So if we have these 2 different URLs: /products/brandA and /products/brandB, I call parameter to "brandA" and "BrandB" in each URL. Now, depending on the parameter being "brandA" or "brandB", I would like to apply one View or other completely different View. The problem I get and where I am stuck is that defining a working URL for a View, you can only define /URL/%, and the placeholder "%" will not discriminate among values of brandA or brandB. If I restrict to putting the exact URL I won't be able to dynamize the URLs and have "kind" of products. – Cesar Feb 18 '16 at 9:16
  • [...continue...] The solution could be to define some kind of token, for example, URL of the View #1: /products/[categoryA] , URL of the View #2: /products/[categoryB] and [categoryA] would be some kind of placeholder for "% but restricted to products of kind A" and [categoryB] placeholder for "% but restricted to products of kind B". – Cesar Feb 18 '16 at 9:19
  • @Cesar so what you're saying is that you have many brands, A, B, C, D, E, F, G, etc.. so making a view page for each of them with an exact url is not ideal? – No Sssweat Feb 18 '16 at 9:26

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.