November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi Sara,
Could you provide a bit more of you code used in the Event, preferably the bit where you use the count that isn't working for you?
I don't "use" the count. EPiServer adds it to the name by default when you create a block from the content area. The name will be:
"Parentsitename blocktype 1" the next one you add (of the same blocktype) will be "Parentsitename blocktype 2".
I want to change the blocktype section to something else, and that part works fine, but it messes up the number after som every block I add gets the number 1.
RightO, I see what you mean with the number now. Still would be good to see a bit more of your code for the updating done.
My guess is that you do a update and then publish the content from code? I guess this will trigger the publishing event again and there by giving you the same object the second time?
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class ContentEventHandler : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
var eventRegistry = ServiceLocator.Current.GetInstance<IContentEvents>();
eventRegistry.PublishingContent += OnPublishingContent;
}
private void OnPublishingContent(object sender, ContentEventArgs e)
{
if (e.Content.Name.Contains("BlockType"))
{
e.Content.Name = e.Content.Name.Replace("BlockType", "NewName");
}
}
}
I have hooked on the PublishingContent event of the IContentEvents to change the given name of a blocktype.
I am replacing a string in the middle of the name, like this:
e.Content.Name = e.Content.Name.Replace(item.Key, item.Value);
The problem is the the count, (the number added last in the name the you create a block from the contentarea), is no longer working. I always get the same number. What am I missing?