A common query about the sitecore tree is how to track down related content. For link fields this is easy to check – the links flyout shows you. Another approach is to use rendering parameters to setup which content item(s) feeds sublayouts, when this is the case the links flyout doesnt display the relationship.
Using the advanced system reporter it is easy to extend the functionality to perform this check. Note, this has been built and tested against Sitecore 6.4.
- Create new filter and custom implementation
- Create new parameter for filter
- If the marketing centre is being used, create new scanner
- Setup the new report
1. Create new filter and custom implementation
Filters can be found at /sitecore/system/Modules/ASR/Configuration/Filters. The class and assembly need setting to match your applications assembly name and class name. Attributes: Value={Value}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
using System; using ASR.Interface; using Sitecore.Data; using Sitecore.Data.Fields; using Sitecore.Data.Items; namespace ###.CMS.Specialization.ASR.Filters { public class RenderingsContainsValue : BaseFilter { public override bool Filter(object element) { Item item = null; string fullName = element.GetType().FullName; item = element as Item; if (item != null) { //check renderings field if (CheckField(item, item.Fields["__renderings"])) { return true; } //check marketing centre data source field if (CheckField(item, item.Fields["Data Source"])) { return true; } } return false; } private bool CheckField(Item item, Field field) { if (field != null) { string fieldValue = field.Value.ToLower(); if (fieldValue.Contains(this.Value.Replace("{", "").Replace("}", "").ToLower())) { return true; } Item searchItem = item.Database.GetItem(new ID(new Guid(Value))); if (searchItem != null && fieldValue.Contains(searchItem.Paths.FullPath.ToLower())) { return true; } } return false; } public string Value { get; set; } } } |
2. Create new parameter for filter
In our code snippet above, we use the parameter Value to query the content items. Create this in /sitecore/system/Modules/ASR/Configuration/Parameters. Note – this was setup to be of type Item Selector.
3. If the marketing centre is being used, create new scanner
Scanners allow for querying the sitecore tree – if you need to check through the marketing centre, setup a new scanner in /sitecore/system/Modules/ASR/Configuration/Scanners.
- Assembly: ASR.Reports
- Class: ASR.Reports.Items.QueryScanner
- Attributes: query=fast:/sitecore/system/Marketing Center/descendant-or-self::*
4. Setup the new report
The last step is to setup the report to use all the filters, scanners and parameters as above. Reports can be found in /sitecore/system/Modules/ASR/Reports.
- Scanners: All items & scanner created in step 3
- Viewers: Item viewer
- Filters: New filter from step 1
Pingback: blog.boro2g.co.uk » Blog Archive » Take control of your sublayouts
Pingback: blog.boro2g.co.uk » Blog Archive » Take control of your sublayouts » blog.boro2g.co.uk