Several sections of the client's website displayed data or assets in a list view and required these queries to be identified ahead of time and with the help of IT. Yet what the client wanted was to control setting the criteria based on which groups of assets were obtained from the CMS.
In short, the content authors knew exactly how things should appear on the pages, but weren't clear about which assets should appear on those pages ahead of time, as this is driven by market and other factors. The default approach was, every time they identified some unique criteria to filter content, they would need a developer to write a module (WebCenter Sites template) that converted criteria into an equivalent WebCenter Sites query. Authors wanted to be able to create them on an as needed basis without the help of a developer.
Here are some simplified examples of what they needed to be able to do:
- Display press releases published in past 6 months sorted by publish date
- Show all the countries in which they operate in alphabetically
- Display products based on a selected category
- List the latest news on the homepage for a few weeks and then switch and show the latest products released for next few weeks
Before getting into the details of the solution, let's briefly evaluate the options available out-of-the-box.
- Query Asset: This allows the user to provide raw SQL queries to access data and fetch it from the CMS. The data can be designed to work seamlessly with the code that renders data on to the webpage. It also, however, requires a developer or a DBA's intervention to setup these queries.
- Writing modules for every possible query. This requires to know all possible queries up-front, so it was not even considered.
We needed to build a solution that allowed the customer a way to setup queries from the Contributor UI, but without dealing with the complexities involved in constructing a query. The outcome was a custom attribute editor using jQuery QueryBuilder widget. We pre-populated the editor with all the asset types, subtypes and attributes available in the system in human readable form, making it easier to build the query using this widget.
- List all articles published in January 2017
- List all products belonging to the North America region
- List all products belonging to the sugar or rice category
The result is a simple and intuitive way to create a query. All types, subtypes, attributes and operations are available in dropdowns menus allowing the user to easily setup queries and less prone to error. The attribute editor automatically converts the queries into equivalent asset queries when the page is rendered and passes the asset ids to the rendering code elements.
Beyond this use case
While this feature was developed to address a specific use case, using this widget provides many additional advantages.
- It reduces the development time and cost. By essentially decoupling the visual aspect of the content from the logic to obtain it, developers can focus on the former while the content authors work on the later thus reducing the overall development time and cost.
- It increases flexibility and efficiency. Content authors can create any number of modules once complete without the help of a developer.