November Happy Hour will be moved to Thursday December 5th.

Setting default name for a shared block

Vote:
 

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?

#112459
Oct 28, 2014 15:32
Vote:
 

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.

#112460
Oct 28, 2014 15:50
Vote:
 

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

#112461
Oct 28, 2014 15:59
Vote:
 

You could have code as:

IContent blockAsContent = this as IContent;

if (blockAsContent != null)

{

//Shared block instance

blockAsContent.Name = "MyName";

}

#112462
Oct 28, 2014 16:06
Vote:
 

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.

#112482
Oct 29, 2014 7:54
Vote:
 

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 ;)

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

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

#112779
Nov 05, 2014 12:50
Vote:
 

Ben, really magic strings here ;)

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

#112783
Nov 05, 2014 13:37
Vote:
 

Haha, well I guess it wasn't intended to be changed. Linus has blogged on the actual XML structure here http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2013/12/New-standardized-format-for-content-type-localizations/

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.

#112785
Nov 05, 2014 13:48
Vote:
 

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

#112786
Nov 05, 2014 13:50
Vote:
 

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?

#112792
Nov 05, 2014 14:57
Vote:
 

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.

#112793
Nov 05, 2014 15:01
Vote:
 

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).

#112795
Nov 05, 2014 15:07
Vote:
 

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.

<contenttypes>
	<teaserblock>
		<newitemdefaultname>Teasy tease</newitemdefaultname>
	</teaserblock>
</contenttypes>

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?

#112891
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.