Try our conversational search powered by Generative AI!

Block

Vote:
 

Hi All 

Might be a newbie question.

We have a case that there will be many blocks that is similar. 

Eg. block 1  is a subset of block 2. 

I wonder if anyone have tried to copy content from one block to another?

#122013
May 25, 2015 18:27
Vote:
 

Hi Johan,

Maybe you could try to prepare generic extension methods responsible for copying one content another. The code could look like this (I didn't tested it - it's just a draft):

public static class BlockExtensions
    {
        public static T Copy<T>(this IContentRepository contentRepository,  IContent sourceContent) where T : IContentData
        {
            var targetContent = contentRepository.GetDefault<T>(sourceContent.ParentLink);
            Copy(sourceContent, targetContent);
            return targetContent;
        }

         public static void Copy(IContent sourceContent, IContentData targetContent)
         {
             Validator.ValidateNotReadOnly((IReadOnly) targetContent);
              foreach (var targetProperty in targetContent.Property)
            {
                var type = MetaDataProperties.GetInterfaceForPageDataMetaDataProperty(targetProperty.Name);
                if (type == null || type == typeof (ILegacyResourceable))
                {
                    var sourceProp = sourceContent.Property[targetProperty.Name];
                    if (sourceProp != null)
                    {
                        targetProperty.Value = sourceProp.Value;
                    }
                }
            }
         }
    }

The method will copy all properties except version specific values (like id, guid, language, etc.)

#122015
May 25, 2015 20:20
Vote:
 

Hi

Cant you use one block as master of all content and them user partials to present them differently, with this approach its easier to structure your content an minimize the amount of blocks?

/Pär

#123450
Jul 05, 2015 0:05
Vote:
 

Pär, by partials you mean to use tagging instructing EPiServer to pick anoter template in different cases?

#123573
Jul 09, 2015 0:14
Vote:
 

Hi

Yes that was my thought.

#123574
Edited, Jul 09, 2015 0:40
* 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.