Can we restrict creating child items for any specific template? - sitecore

I have 2 templates Template 1 and Template 2. Template 2 is the child of Template 1 and Template 1 is going to be the parent one. But the requirement is to disable creating any items under item derived from child template. When we right-click on Item I want to disable "Insert From Template" option for this specific child template only. If I alter the core database to remove "Insert From Template" it would be applied to all items which is not required.
Is there any other way or suggestions that can help me here?

You could probably restrict the creation by extending the item:created event. Here's an example: Sitecore Insert rules to ensure at most (1) children of a certain type. The idea is, you display a message in the UI if the user tries to create an item under an item of a certain type.
It may also be possible to do it with insert rules, but you might not be able to remove the Insert from Template option itself. For more info on insert rules, check out part 5.4 (page 35) of the data definition cookbook: https://sdn.sitecore.net/upload/sitecore6/60/data_definition_cookbook_sc62-a4.pdf.

Related

Oracle APEX - make a field conditionally required

I have an item that is displayed conditionally - based on another item selection. I want to make that item non-required when hidden. What is the best way to do that?
As you have probably found, you cannot just set the dependent item's Required attribute, as this makes it required even when hidden. Instead you can create a Validation of type "Item is NOT NULL" on the dependent item, but with a server-side condition based on the value of the other item.
For example, suppose the first item is P12_JOB and the second is P12_COMMISSION, and P12_COMMISSION is only shown when P12_JOB = 'SALESMAN'. Then this Validation will do it:
As you can see there are various settings available there that you should check are appropriate for you e.g. Always Execute, Display Location.

Defining template field types for Sitecore content items which contain sub-items

In my Sitecore MVC project, is it possible to define a template for a Sitecore item in such a way that the content item is linked to some number of "sub-items"?
For example, say I want to define two templates - one called User and another called UserGroup.
A User has two fields: Name and Age.
A UserGroup has three fields: User #1, User #2, and User #3.
Two questions:
The User template would make use of the Single-line text and Integer field types. But for UserGroup, what types would be used for the User1 field (for instance)? Could I use User as a type? If not, does it make sense to store a GUID which points to the individual User content items that I want to reference?
Is this approach considered an anti-pattern? Is it possible to pull off something like this by nesting the content items inside of each other in the Sitecore content tree? If so, how would the template have to be configured?
For the User #1, User #2, and User #3 you can use a drop link field. The datasource will point to the parent item of User items. User is not a type, is an template. You can consider User as a class and items of type User are objects.
I suggest you to download launch Sitecore from http://launchsitecore.net/en/download and install it on a clean solution to see how others are structuring items in Sitecore.
Update
You can have next structure
User #1 , User #2 and User #3 have datasources: ./
If one user can be assign to multiple user groups I suggest to put all users under a global item and the User #1 , User #2 and User #3 will point to that item.

Content migration from one template to another in Sitecore

I want to transfer content of items that belong to one template into another template.
For example, I have 5 fields in first template:
Tags
Image
Download link
Title
Date
and 5 fields in another template:
Type
Picture
Download Text
Title
Date
Here first two fields are different in the both the templates and remaining 3 fields are same.
So I want to migrate content of items that belong to first template to the second template. Also, I would like to highlight second template is a newly created template and currently no item from that template is created. So ultimately I am modifying the template of 100 items.
I tried overriding change template method of sitecore TemplateManager.ChangeTemplate(Item item, TemplateChangeList changes) but it empties the fields rather I want to retain the field data.
If anyone has any idea about this, please help.
I don't think there wouldn't be much difficulty to migrate all contents by changing the template. But, the main issue is that there are a number of page items which have to be changed to another template.
If you do, you can use PowerShellExtension. It takes only 1 second.
You can get the script idea from Sitecore Workflow Is Not Working
A solution is to inhertitance this fields, (using the "Base template" Field).
A other solution is to create your own change template command.
You can found here sample code: http://sitecore.stockpick.nl/nederlands/dialoge-box-in-een-command/ (it is a dutch article)
In code use: item.ChangeTemplate(template); and fill in the new field with the already stored values from the old template.

How to use Droplist types in Sitecore template fields

Is there anyone who knows how to use "Droplist" type in template fields?
I guess "Droplist" is the same as <select><option></option></select> type.
I'd like to specify select list types with static values so that Sitecore editors can select only one of many available lists when they create a page.
My plan is to add CSS class names (<option>) in the list (<select>) and editors will use one of styles by selecting one of them.
How to add the values in select list? Do I have to write code?
The Droplist is similar to the Droplink field type in that they are both dropdowns. The Droplist will only store the name of the item (so it will not have a link to that item), while the Droplink stores the ID of the item. That means if you rename an option, or move it elsewhere in your Content Tree, the Droplist will not update (resulting in possible broken links), the Droplink will update.
You can add values to the Droplist by setting the Datasource field in the templates to something (for instance /sitecore/content/Home/CSS/ if that's where you would like to store your CSS class names).
You can access the Droplist in code like so:
Item item = Sitecore.Context.Item;
string css = item["FieldName"]; // Also possible is item.Fields["Fieldname"].Value;
A Droplink could be accessed like this:
string dropDownItemId = item["Fieldname"]; // Or, again, item.Fields["Fieldname"].Value; if you prefer
var cssItem = Sitecore.Context.Database.GetItem(dropDownItemId); // And now you can
// access any fields in this item.
Edit
A good article going into some more detail in the differences between Droplink and Droplist
I would proceed exactly as #Trayek suggested in his solution. To expand on that, this should be your implementation:
You create your own template, maybe called CSS Class, and you will add a Single-Line Text field to it, maybe called Value. You will put the actual CSS classes in that field when you create the items.
Next, you will add a folder item somewhere in the Content tree, and you will add your CSS Class items to that folder. That folder will also be the datasource of your droplist/droplink.
To set your datasource, this blog post should be of help. You will be looking to use number 1 under For Fields without Search (screenshot included, below). I wrote the article a while back, so if you need any additional help just let me know.

Sitecore values -- Template > Standard Values > Branch > Item

OK, here's the process I took...
create a new template "Mail Message"
create a "__Standard Values" item for the template
edit the "Subject" field in the standard values item: "Monthly email newsletter"
create a branch for the template
do NOT set the Subject field in the branch item
create an item from the branch
I would expect the subject would be the one from the standard values item, however it seems the branch field value is blank, and in turn the created item also has a blank subject field.
Should the Branch field value be that of the standard value. Or does the very act of creating a branch item eliminate any standard values you set.
Does the field versioing have any effect (e.g. Shared, Unversioned)?
I haven't been a big user of Branches, so I am surprised at the behaviour, but if it is normal, all good. Just want to confirm.
Alternatively, if the template or standard values were locked when the branch or item was created, the standard values might not have carried through.
Either way, you need to reset the value of the sitecore item. On the item, click the 'Reset' button, which is under the Versions tab and check the checkbox next to 'Subject'. Now, the field will show as 'Subject [standard value]'.
Hope that helps!
Creating the branch for the item template should copy the standard values and allow you to update the default values from the template.
So for example if you had "Monthly email newsletter" in the "Subject" field of the template it would be the same in the branch and all items created from that item.
Changing that field in the Standard Values should then update it in the branches and items.
If you have changed the field on the item however the link would be broken and you would no longer manage it from the standard values with out resetting the values.
Not sure on the shared/unversioned factor but dont think it effects the standard values.
When you change the value in branch template, you've broken the link already. So after that if you change the standard value, the value in branch template will not effect