How to remove “Insert from Template” option in Sitecore

Let’s face it! You can’t always satisfy business needs in the happy case scenario of doing things where all you need to do is one, two three and voilà everyone is happy. Specific business cases sometimes need workarounds and more line of codes to implement but they are always possible in Sitecore.

One of these cases that we were up to was to remove the “insert from template” option for a certain site in a multi-micro site environment. There are many ways of doing this, some that would affect the entire solution and some that would affect certain users, but what if I need to remove this option even from Sitecore Administrator and do it only for certain templates!

Option 1:

For the first glance, permissions would be the best and perfect option to do this where all you need to do is to remove the read permission from the insert options for certain users. To do this:

    1. Switch to the Core database.
    2. Navigate to /sitecore/content/Applications/Content Editor/Menues/New/Insert from Template item.
    3. From Security tab, select assign and the below screenshot will popup up. Revoke the read permission for any user/role you wish to.

Option1-SecuritySettins

This option will remove the “insert from template” option from the entire site for those specific users/roles and yet we didn’t solve our problem.

Option 2:

You can remove or just relocate the “insert from template” option from /sitecore/content/Applications/Content Editor/Menues/New/Insert from Template. This will serve as option 1 for all users/roles and for the entire site in a single step and having the same conclusion.

Option 3:

Use a command template to implement the same functionality of option 1. To do so you need to navigate to the template you wish to remove the “insert from template” option from and:

  1. Insert a definition item for the command template using the System/Branches/Command Template data template.
  2. In the Command field in the data section add item:addfromtemplate(id=$ParentID).
  3. Implement the command template, you can reference this for more details http://sdn.sitecore.net/upload/sitecore6/datadefinitioncookbook-a4.pdf.
  4. Finally, move, delete, or deny read access for the Everyone role in the Sitecore security domain to the “Insert from Template” item in the Core database.

As you can see that although you can do it programmatically, you still need to configure the Core database and affect the entire site. Sigh!

Are we running out of options to solve this scenario? …. What if I build how the menu looks like in Sitecore and just remove the “Insert from Template” option, is that possible?

Option 4:

Well, absolutely. You can re-build the menu item for Sitecore just by overriding the ItemNew command. “ItemNew” command is triggered whenever you need to create a new item based on another item (template). The basic idea to solve our problem is

  1. When right-click on a certain item, check whether the current item is created from the template we wish to remove the “insert from template” from.
  2. If this item fits the criteria, check if the current menu list item is the “insert from template” item.
  3. Remove the code for inserting this option.

This way, we can ensure that all users are not able to choose any other template to create items for certain sites than those assigned in the insert options. Moreover, we can apply this to any item in any level of the Sitecore tree without affecting other items or sites.

To implement this you need to:

  1. Create a class that overrides the “ItemNew” command.
  2. Override the GetSubmenuItems function with the code below by:
      1. Retrieve the insert options assigned to the current item.Option4-OvverideInserNewItem-1
      2. Check for the “insert from template” option ID and do not add the menu items.Option4-OvverideInserNewItem-2
  3. Replace the “ItemNew” command in \Website\App_Config\ Commands.config with the new one.

<command name=”item:new” type=”YourProject.InsertFromTemplate.RemoveInsertFromTemplate, YourProject ” />

And that’s it… you can insert new items without the “Insert from Template” option🙂

One thought on “How to remove “Insert from Template” option in Sitecore

  1. Pingback: Re-blogged: How to remove “Insert from Template” option in Sitecore | Sitecoring

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s