Try our conversational search powered by Generative AI!

Eventhandling

Vote:
 

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?

#85693
May 02, 2014 10:44
Vote:
 

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?

#85702
May 02, 2014 11:38
Vote:
 

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.

#85713
May 02, 2014 12:53
Vote:
 

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?

#85725
May 02, 2014 14:55
Vote:
 
    [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");
                }
        }
    }

    

#85753
May 05, 2014 8:33
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.