3

We are using out of the box item name functionality in Sitecore. We are also using $name to add that to the title of the page. Our client would like to have the following happen. They would like to create an item and add the title of the item as-is in the name dialog that shows up. They would then like the proper alphabets/numbers and hyphens automatically created in the item name and the title copied as is to the title field.

Is anything like this possible? I haven't seen any code examples/samples for this kind of functionality.

Thanks

2

1 Answer 1

4

Well you could extend the item:added event to then take the item name and update the title to have a formatted item name minus all the special characters.

You would need to do a check to ensure the item that you are adding has a field called Title or else it would fail. This probably isn't the most efficient and elegant solution because you are basically calling this code on every item add event. You could alternatively choose extend the custom standard values tokens, such as $id or $parentname and create your own called $nameclean.

To extend this token replacement, you would patch the Setting MasterVariablesReplacer and set it to a class that you'll create that will just extend from the existing Sitecore.Data.MasterVariablesReplacer, Sitecore.Kernel.dll. If you decompile the Sitecore.Kernel.dll you can see the original source to that dll. Then you can add an additional line to replace this new custom token that you created. Then all you would need to do is add to the Title field for your Template, to the StandardValues $nameclean, and when your item is created from this template it will generate the name you seek.

1
  • 4
    Don't forget to check the InvalidItemNameChars and ItemNameValidation settings in your Sitecore.config file. This to setup the allowed characters and a correct validation respectively.
    – Koen Heye
    Commented Nov 14, 2016 at 21:57

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.