Item Naming rules

  0 rating
CMS;Developers
3/22/2013 2:33:01 AM
3/22/2013 2:33:01 AM
Provider: Sitecore

About

The ItemNamingRules project provides conditions and actions for the rules engine to automate item name conventions.

Documentation

Documentation
  • Documentation > Getting Started with the Item Naming Rules
    Getting Started with the Item Naming Rules

    The ItemNamingRules project provides conditions and actions for the rules engine to automate item name conventions. You can use the ItemNamingRules project to apply different item naming rules in different branches of the content tree. For more information about the rules engine, see the ​Rules Engine Cookbook.

    With the provided conditions, you can:

        * Invoke actions if an item has layout details for the default device.
        * Invoke actions if an item has layout details for any device.

    With the provided actions, you can:

        * Replace any character that does not match a regular expression with an alternate string.
        * Merge sequences of invalid characters into a single instance of the alternate string.
        * Remove leading and trailing instances of the alternate string.
        * Restrict the maximum length of item names.
        * Ensure unique item keys (names).
        * Lowercase item names.

    For example, you can configure an item naming rule such that if an item descends from the /Sitecore/Content item, and that item has layout details, then the name of the item must contain only lowercase letters, numbers, and underscores, cannot contain two sequential underscores, cannot begin or end with an underscore, cannot exceed 35 characters, and must not have any siblings with a common key. The ItemNamingRules project automatically renames the item, appending a datestamp if required to ensure unique keys.

    You can use additional techniques to meet specific objectives when controlling item names. You can configure the InvalidItemNameChars, ItemNameValidation, and MaxItemNameLength settings in web.config, but these settings apply to all items rather than to items matching specific criteria. You can use pipelines to interact with CMS users when they invoke operations that affect item names, prompting the user to correct errors instead of correcting them automatically. You can also use validation including validation actions to flag and correct naming issues.

    Note: The ItemNamingRules project will not rename standard values items, or the home item of any of the managed Web sites.

    Configuration

    Compile the code into your Visual Studio Web application project.

    To register the conditions, in the Content Editor, insert condition definition items beneath the /Sitecore/System/Settings/Rules/Common/Conditions/Fields item using the System/Rules/Condition data template:

    Name: When the item has layout details for the default device
    Text: when the item has layout details for the default device
    Type: Sitecore.Sharedsource.Rules.Conditions.HasLayoutDetailsForDefaultDevice, Assembly

    Name: When the item has layout details for any device
    Text: when the item has layout details for any device
    Type: Sitecore.Sharedsource.Rules.Conditions.HasLayoutDetailsForAnyDevice, Assembly

    To register the actions, in the Content Editor, insert action definition items beneath the /Sitecore/System/Settings/Rules/Common/Actions item using the System/Rules/Action data template. To help users select actions in the correct order (for instance, validate all characters before validating length), order the actions as follows:

    Name: Replace Invalid Characters in Item Name
    Text: replace characters in the item name that do not match the regular expression [MatchPattern,Text,,MatchPattern] with [ReplaceWith,Text,,ReplaceText]
    Type: Sitecore.Sharedsource.Rules.Actions.Naming.ReplaceInvalidCharacters, Assembly

    Name: Ensure Minimum Length of Item Name
    Text: ensure a minimum name length by appending characters from [DefaultName,Text,,DefaultName]
    Type: Sitecore.Sharedsource.Rules.Actions.Naming.EnsureMinimumLength, Assembly

    Name: Ensure Item Name is Unique and limit length
    Text: ensure item name is unique and does not exceed [MaxLength,int,,maximum length] characters
    Type: Sitecore.Sharedsource.Rules.Actions.Naming.EnsureUnique, Assembly

    Name: Lowercase Item Name
    Text: lowercase letters
    Type: Sitecore.Sharedsource.Rules.Actions.Naming.Lowercase, Assembly

    To manage item naming rules, in the Content Editor, select the /Sitecore/System/Settings/Rules/Item Saved/Rules item. Insert rule definition items using the System/Rules/Rule data template. In the Rule field, click Edit Field, then select conditions, then add actions (in the order listed), and then enter paramters for the conditions and actions:

        * MatchPattern - Regular expression for validating each character. For example, ^[A-Z|a-z|0-9|_]$.
        * ReplaceText - Character or string for replacing invalid characters. For example, _.
        * DefaultName - Characters to use to replace invalid characters in item name. Also defines minimum item name length. For example, given DefaultName 12345, the action will rename the item named A to A2345.
        * MaxLength - Maximum item name length. For example, 25.
        * Device - the device for which the rule applies.
      



Back
Release notes
The module was added 18-09-2009
Read more Back
Code examples

Solution screenshots(0)

Upload

Reviews (0)

Sort by: Date Most votes
  • Profile Avatar
    [fullName]

    Level: 0

    x0 x0 x0

    [date]

    [title]

    [text]

    Was this helpful?

    0

Comments (0)

Sort by: Date  Most votes

Leave a Comment

Comment must be field in
Post comment
loader

Write a review

Title can't be empty
Review can't be empty
Post review

Download

Title Description Download Action

Add File