开发者

In Sitecore, how to create a new item based on an existing item

开发者 https://www.devze.com 2023-04-12 10:52 出处:网络
I am new to Sitecore. In Sitecore I need to enable users to create new items based on existing items. I am envisioning something like this:

I am new to Sitecore.

In Sitecore I need to enable users to create new items based on existing items. I am envisioning something like this:

  1. the user clicks "insert" in the context menu
  2. the user is prompted for another item somewhere in the tree (it must be based on a specific template)
  3. A new item is created with some fields pre-populated with the values from the original item
  4. The user can now fill out other fields which are not pre-filled - or change the pre-populated values

(notice that the new item is based on another template than the original). I do not have worry about changes to the original item - they do not need to be propagated to the new item.

As a beginner I don't know how to 开发者_如何学Pythondo this. I have looked at various options:

a. Clones. Clones seemed to be close to what I want, but I can't have extra fields on the new item, and they can't be based on different templates. So I guess its not really a clone I am after. (also, they are pretty new to Sitecore)

b. events. I think I should be able to intercept the "new item" event, but I have no idea how I would then throw up a dialogbox and ask the user to select an original item.

c. Reference to original item. I have figured out how to create a field that can contain a reference to the original item. However, how do I populate fields when the user sets it - and how can I make sure the user starts with this field before doing anything else?

I have also looked into commands, hooks and more ...

So? Any ideas?


This would be a particularly significant undertaking and if you're new to Sitecore, it might be extremely difficult.

I would suggest looking into customizing the client (this can be accomplished by editing the Core database from the Content Editor as well as implementing some things in code)

If you have access to the Sitecore Developer Network, this will be helpful: http://sdn.sitecore.net/Reference/Sitecore%206/Client%20Configuration%20Cookbook.aspx

These articles might give you some additional ideas about implementation:

  • http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/Add-a-Command-to-the-Sitecore-Item-Context-Menu.aspx
  • http://learnsitecore.cmsuniverse.net/en/Developers/Articles/2009/10/My-First-Sitecore-XAML-Application.aspx
  • http://www.markvanaalst.com/sitecore/creating-a-item-editor/
  • http://sdn.sitecore.net/Articles/XML%20Sheer%20UI/My%20first%20XML%20application.aspx
  • http://sdn.sitecore.net/Articles/Customizing%20Sitecore%20Client/Creating%20XML%20Application.aspx

The first article might be your best bet for adding a context menu item. You can execute commands in your compiled code by doing the following:

  • In your Commands.config file, add an item such as <command name="button:copycreateditem" type="Your.Namespace.And.Classname,Your.Assembly" />
  • Create a class in the Assembly and Namespace you specified with the correct Classname
  • Inherit from `Sitecore.Shell.Framework.Commands.Command
  • Implement the method Execute(CommandContext context)
  • Build

The CommandContext will provide a lot of the necessary information you'll need to make your changes (such as currently selected item).

Hopefully this will put you on the right track. Good luck!


I don't really understand what you're saying with "it must be based on a specific template" and then later "the new item is based on another template than the original". Not sure how you can have it both ways, so my answer assumes that you're sticking with one template.

The standard sitecore way to do this is to assign standard values in templates. The user can then create a new item based on a template, and the standard values will come across.

To create standard values for a template,

  1. select the template
  2. go to the "Builder" tab on the ribbon
  3. Click on "Standard Values"

This will create a new item "__Standard Values" under the template where you can setup default values for some fields and leave others blank.


Insert options, insert rules, nvelocity tokens ($name), and template standard values.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号