5

Bucketing is a nice feature for organizing a large amount of items in the Sitecore content tree, however the default bucketing strategy based on item creation date is mostly useful for content where the creation date is actually relevant (e.g. news articles).

Can multiple bucketing strategies co-exist in the same Sitecore solution? Is it possible to create a different bucketing strategy based on the bucket item template?

2 Answers 2

2

You are able to change the format of the default bucketing folder structure uising the following setting:

<setting name="BucketConfiguration.BucketFolderPath" value="yyyy\/MM\/dd\/HH\/mm"/>

Note that this is still based on the item creation date though.

It is also possible to utilise the Sitecore Rules Engine to determine the folder structure, updating the rules on /sitecore/system/Settings/Buckets/Item Buckets Settings in the content tree.

Out of the box the following rules are available:

Sitecore Buckets Rules Editor

The first rule is pretty much the same as the default naming using config settings, but it does allow you to set a different format per bucket folder. The other 2 rules use the item ID or name and then create nested folders based on that.

If none of rules meet your requirements then it is possible to create a custom rule and utlise that instead. For example, to create the folder based on the user creating the item and the year you could use:

public class UserBasedPath<T> : RuleAction where T : BucketingRuleContext
{
  public override void Apply(T ruleContext)
  {
    if (Sitecore.Context.Data != null && Sitecore.Context.Data.User != null)
    {
      ruleContext.ResolvedPath = 
        Sitecore.Context.Data.User.LocalName + "/" + DateTime.Now.Year;
    }
  }
}

You will need to register the rule under /sitecore/system/Settings/Rules/Definitions/Elements/Bucketing and set the Text and Type fields to match your rules and the it will be available for use in the Rule Set Editor.

3
  • Is this approach preferred over dynamic bucket folder?
    – Kasper
    Commented Oct 4, 2016 at 10:41
  • @KasperGadensgaard It depends on your requirement. If all your bucket item folders need to be in exactly the same structure then BucketConfiguration.DynamicBucketFolderPath setting is a good option. However, if different bucket folders have different folder structure requirements (e.g. news items vs blog posts) the using the Rules Engine to set these is preferable.
    – jammykam
    Commented Oct 4, 2016 at 10:44
  • I need different bucketing strategies per template, so it sounds like this is the way to go.
    – Kasper
    Commented Oct 4, 2016 at 10:53
1

You can implement Sitecore.Buckets.Util.IDynamicBucketFolderPath to make your own logic. There is one method to implement, where you have templateId - among others - as a parameter:

string GetFolderPath(Database database, string name, ID templateId, ID newItemId, ID parentItemId, DateTime creationDateOfNewItem);

Then point the setting BucketConfiguration.DynamicBucketFolderPath to your class.

2
  • So setting the BucketConfiguration.DynamicBucketFolderPath will ignore the setting of BucketConfiguration.BucketFolderPath?
    – Kasper
    Commented Oct 4, 2016 at 10:09
  • @KasperGadensgaard If you don't plan to use it in your logic, yes. It is used by the default BucketFolderPathResolver and by the DateBasedFolderPath implementations. Another predefined bucket path resolver is GuidFolderPath.
    – Thomas D
    Commented Oct 4, 2016 at 10:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.