SaaS CMS has officially launched! Learn more now.

Setting default name for a shared block


Does anyone know how I can set the default name of a shared block? The standard way of overriding SetDefaultValues(ContentType contentType) in the class declaration does not work since blocks by default do not implement IContent. Does anyone have a solution for this?

Oct 28, 2014 15:32

SetDefaultValues is not part of IContent. It is definied on interface IInitializableContent which is implemented by ContentData (which BlockData inherits). So overriding of SetDefaultValues should be possible for blocks.

Oct 28, 2014 15:50

SetDefaultValues is a valid override for block classes, and works for other properties on them, but not on the block name.

Oct 28, 2014 15:59

You could have code as:

IContent blockAsContent = this as IContent;

if (blockAsContent != null)


//Shared block instance

blockAsContent.Name = "MyName";


Oct 28, 2014 16:06

I have tried to code it the way you are proposing Johan, but it doesnt work. I still get the popup asking me to specify a better name than "New Block" when I try to create the block.

Oct 29, 2014 7:54

If you want to change the "New Block" name that is set when creating blocks via the UI then you can change it by overriding that specific key in the language files. Since the default name is language specific, it is therefore stored in the language files ;)

    <language name="English" id="en">
                <newitemdefaultname>Please enter a name for this block</newitemdefaultname>

You can do the same for pages with a pagedata node or folders with a contentfolder

Nov 05, 2014 12:50

Ben, really magic strings here ;)

Would be nice to be able to set this through code though

Nov 05, 2014 13:37

Haha, well I guess it wasn't intended to be changed. Linus has blogged on the actual XML structure here

It is the same structure for when you want to localize the name or description of a content type. But in this case we add the localizations to the base types; PageData, BlockData, ContentFolder.

Nov 05, 2014 13:48

What I meant was the newitemdefaultname element which I've not seen any documentation on :\

Nov 05, 2014 13:50

Setting newitemdefaultname doesnt seem to work correctly, when the block is created the name in the top left input field is still "new block", but when the user doesnt change the name, the value of newitemdefaultname is shown in the popup asking the user to change the name to something better than "new block". This means the editor still has to change the name. Any other solutions to this problem?

Nov 05, 2014 14:57

Consider that EPiServer can't know what the default name should be in the first step since you have not yet selected which content type you want to use.

As you say, the suggestion to name will be your provided default name unless the editor starts with editing the name.

Nov 05, 2014 15:01

Obviously i'm not expecting episerver to know the default name before a content type has been selected, but episerver should be able to know the default name after I have selected a type, since this works for pages right now (by overriding SetDefaultValues and setting PageName).

Nov 05, 2014 15:07

Just because EPiServer asks the editor to change the name to something better than "new block" (or in Ben's example "Please enter a name for this block"), it doesn't mean that the user must change name.

In my example I could use the following to work but EPiServer seems to have the resources cached for a while.

		<newitemdefaultname>Teasy tease</newitemdefaultname>

and the editor can select "Teasy tease" even if EPiServer says "Consider renaming the content to something more descriptive than default."

However I'm not able to set the PageName using SetDefaultValues. I'm testing in Alloy and 7.16. Which version are you running on?

Nov 06, 2014 22:50
* 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.