Sitecore URL Optimization

Working with multiple language sites in Sitecore 6.2 I would like Sitecore to replace the "" (white space, traditionally replaced with% 20) in the URLs with a hyphen.

eg. www.MySite.com/Hello World> www.MySite.com/Hello-World

There is still no problem, we just add another entry to encodeNameReplacements

<replace mode="on" find=" " replaceWith="-" /> 

Then, so that our content authors do not create hyphenated elements in their names (which Sitecore would understand as free space when reading its URLs, resulting in 404 Not Found), we can add a hyphen to the list of prohibited characters in element names using

  <setting name="InvalidItemNameChars" value="\/:?&quot;&lt;&gt;|[]-"/> 

All this works great - until I try to create a new definition of the language. Languages ​​in Sitecore can use a simple language code (for example, en, da, de, etc.) or a language and region (ISO) code such as en-GB, da-DK, de-DE, etc. For our sites, we will need regional codes, as we intend to support regional language variations (for example, Swiss French and Swiss German). But, of course, now I have forbidden a hyphen in element names (and languages, like everything else in Sitecore, are defined as elements). In fact, Sitecore requires the language name to be correctly constructed as a culture identifier, so I can not assign the language a descriptive name (for example, American English) with the iSO code specified in the ISO code field of the template.

Can anyone suggest a suitable solution? Should I remove the hyphen from the InvalidItemNameChars node and write my own piece of code that the traps tried to create the names of the portable names i? If so, how should I interecpt the creation event?

I don’t like to configure the interface where it’s not needed, especially since I can worry that this may create problems for updating the version of Sitecore, so if there are other solutions, I would like to hear them.

Thanks in advance.

+4
source share
2 answers

This uses a rule engine to replace special characters, such as spaces in element names:

https://marketplace.sitecore.net/en/Modules/Item_Naming_rules.aspx

If you didn’t replace, but simply translate when you processed the URLs, the Sitecore element converter would try to search for element names with dashes, not spaces, and would not find suitable elements. If you are not actually replacing characters, you need to override the element recognizer.

If you want to leave names with spaces visible to the user, but actually name the elements with dashes, you can set the display name for the element to its original value with spaces when renaming spaces in the dash, but I would recommend against this.

+4
source

You can write a class and place it in the stored item event in the web.config file. Just write the OnItemSaved method and ask it to check the hyphen in the name. I think you will need to do this when renaming, and on the copy.

 <event name="item:saved"> <handler type="Sitecore.Links.ItemEventHandler, Sitecore.Kernel" method="OnItemSaved" /> <handler type="Sitecore.Tasks.ItemEventHandler, Sitecore.Kernel" method="OnItemSaved" /> <handler type="Sitecore.Globalization.ItemEventHandler, Sitecore.Kernel" method="OnItemSaved" /> <handler type="Sitecore.Rules.ItemEventHandler, Sitecore.Kernel" method="OnItemSaved" /> <handler type="YourAssembly.ItemEventHandler, YourAssembly" method="OnItemSaved" /> </event> 
+3
source

Source: https://habr.com/ru/post/1334917/


All Articles