Search

I have one page, lists, with two URL params, like so: lists/$category/$list_id/.

  • Visiting lists/ with no params set should display a list of categories.
  • Visiting lists/$category/ with no $list_id set should display all the lists in $category. If the category with handle $category doesn’t exist, throw a 404 error.
  • Visiting lists/$category/$list_id/ should display the list with System ID $list_id$. If the list with ID $list_id doesn’t exist, throw a 404 error.

This works as intended except that I can’t get the 404 logic working properly with my data sources.

I have a “Reading > Lists” data source that will filter the lists based on $category. If I set $category as a required URL parameter and tick “Redirect to 404 page when no results are found,” then visiting lists/ throws a 404 error, because $category is not set, so the data source returns an empty result. If I remove the required parameter, however, then every list shows up in the XML for lists/. Although this is not visible to the end user, it feels wasteful to me, and it poses a potential performance problem as my number of lists increases, yes?

I guess what I’m trying to express is this logic: “If $category is set and “Reading > Lists” returns no result, then throw a 404.”

I’m having a similar problem with the data source for retrieving a single list, “Reading > List” (I have two because I don’t need all the data from a list to display it on the category page.) Again, I want it to say, “If $list_id is set and “Reading > List” returns no result, then throw a 404.”

Have I made it all too complicated? Is there a simple way to do this that I’ve overlooked? If not, I’m not averse to editing the data source to add the above logic if possible.

Rather than show a generic 404 page why not test for no-results and display an informative message to your visitor on the same page that you would have listed the results: “Category $category produced no results.”

@Nils: Thanks! That’s the kind of trick I needed. I’ve got it working the way I want now.

@wisolman: That’s a good idea and probably what I would have done if the workaround was too cumbersome. However, it’s not just a matter of producing no results; the category itself doesn’t exist. Semantically, that seems more like a 404 error to me than, say, a search that produces no results. I’m open to an argument to the contrary. Fortunately, this is a personal site, so only my ego suffers if I’m wrong.

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