Customized Sitecore Search View - List Buckets Values in Dynamic Placeholders
Many of you know this problem: We have a bucket containing items and we want to visualize the items in a list with all values and not only the standard properties like:
- Template
- Location
- Version
- Created
- By
- Language
The magic words to do this, is "Dynamic Placeholder"!
What we have
1. Template "Order Programme Form"
The field "Bucketable" of the standard values of the template must be set to "true".
2. Bucket containing items of template "Order Program Form"
With the following Settings:
- "Is Bucket" to "true"
-
"Persistant bucket filter" is the preset filter, which can't be changed in the Sitecore search.
You can separate the with a semicolon and the "+" means a logical AND.
I recommend: Set the location to the folder itself, otherwise it finds the items outside the folder too.
And filter on the template "Order Programme Form", otherwise other item types or folders could be found also. - "Enabled views" is set to the view which we will create later in the next step. It should be set to this view as default.
Here is how the Persistant bucket filter look like:
What we have to do
1. Configuration File
- root = ID of the folder containing the buckets
- template = ID of the "Order Programme Form" template
- maps = every field of "the Order Programme Form" template
- fieldId = ID of the matching field in the template
- dynamicViewName = must match the name of the DynamicPlaceholder in the view we want to create later
2. Custom Bucket View
We create our own View:
Under Settings/Buckets/Views we make a new View called "Order Programme View".
We can build the table view with plain HTML and thus control how the table should look like in the following three sections:
- Header
- Item
- Footer
Here are the three samples of the HTML code:
- Placeholders are SystemPlaceholders (for other available SystemPlaceholders take a look in the standard table view)
- DynamicPlaceholders are the placeholders from the configuration file
3. Custom Bucket Facet (Optional)
We wanna filter our search also on the field "Lang"
Under System/Settings/Buckets/Facets we create our own Facet: "Lang"
When completing a search, there is now a new facet called "Lang".
4. C# Code
Model for the "maps" in OrderProgramme.config
In OrderProgramme.config we also declare a pipeline for "buckets.dynamicFields":
The source code for the configured pipeline:
Please keep in mind to change to code where we get the configuration item to your own implementation.
Voilà!