1

Views require "Use AJAX" in order to display exposed filters when using Block display. I think this is necessary to avoid submitting/influencing other form elements on the current page.

I have a page that is a View but my page has to have a certain route name because my app relies on it. So I've used Block display for the Views instead of the Page display.

But I want the user to see the filtering arguments in URL so he can save the search or link to it. So obviously I will have to use the Page display for my view. But how can I use the Views with mine route?


Is is a good idea to create a Page view with some dummy path and load the View's route and get it's content and display it via mine route controller?


At first I've used the config option mentioned by Daniel Wehner but I ended up with using a custom filtering form + query tag. This gave me much better flexibility and customization options than Views' exposed filters.

0

1 Answer 1

3

There are a couple of things you can try out:

  1. Write a display plugin for views which extends the page one and allows you to specficy the route name in the UI. Note: views already uses a option in the view yml file 'route_name' if it is available:

    display:
     page_1:
       display_options:
         path: node
         route_name: hallo_world
    

    So you could just hack your yml file and be done.

  2. Use the route alter event and simply rename the route generated by views:

    protected function alterRoutes(RouteCollection $collection) {
      if ($route = $collection->get("view.$view_id.$display_id")) {
        $collection->remove("view.$view_id.$display_id"); // not sure about the method name.
        $collection->add('hey.this.is.my.cystom.route.name', $route);
      }
    }
    
  3. Be okay with the name views generates, as it won't change over time.

4
  • No idea but I don't get the code to look like code, anyone with an idea how to do it? Commented Apr 26, 2014 at 9:01
  • 1
    This post explains how to make code work in lists. Essentially just more indention...
    – Felix Eve
    Commented Apr 26, 2014 at 9:24
  • I've used the #1 approach and works like a charm. I get why this is hidden from the UI but this really needs to be mentioned in the documentation later on when 8.0 will be out.
    – user21641
    Commented Apr 26, 2014 at 14:43
  • I will not fight that but some people just have a different thoughts about enpowering people than I do have Commented Apr 26, 2014 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.