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.
Related
In dotCMS,
1) I Created a content type with name product with 3 fields (name, id, description). Name and id fields created by selecting unique option. Name and Id fields combination should give uniqueness. But in dotCMS there is individual field unique option. When I try to add new content with below data it is failing to insert .
a) name: prod1, id : 1, description: phone.
b) name: prod2, id: 1, description: tablet.
2) While calling REST api to save/publish a content, is there any way to pass multiple input instead of single PUT or POST. https://dotcms.com/docs/latest/rest-api-end-points#ContentResource
Is there any solution for above two problems?
The Unique option applies only to a single field, and ensures each content item has a Unique value for that field only. There's no built-in way to check for uniqueness on multiple fields.
However one relatively simple way to do what you want is to create a separate custom field that automatically fills with the value of the name and ID fields (just append the value of the two fields), and then just set the Unique flag on the custom field. For more information on custom fields, see https://auth.dotcms.com/docs/latest/custom-field. Note that the dotCMS starter site includes many custom fields you can use as examples as well.
I'm not sure what you mean. If you mean can you make a single REST call to create or update multiple individual content items, then the answer is no - you need to do a separate REST call for each item you want to create or update. (So you'd either need to code a loop to create each piece of content, or use another method such as importing content using a CSV file).
If that's not what you mean, can you please clarify your question?
I am using the Dynamic Placeholders from Fortis, but need to setup a page template where the Dynamic Placeholders contains renderings. I am setting the page template up, by setting layout detail on the standard values of the page template.
I have been unable to succeed in this, since the dynamic placeholder is postfixed by a GUID which is generated. Is there a way to predict this GUID? According to the documentation, the GUID is generated using the following logic:
Dynamic Placeholders simply use the rendering ID to create a unique placeholder name. If more than one dynamic placeholder with the same name is in a rendering it will also append on an incrementing number
I tried another approach, by using a home brewed dynamic placeholder library, which just prepended the dynamic placeholder with a sequential number, e.g. row1, row2, row3. But this approach makes the content editors unable to move rows in the experience editor, since the content inside the row is tied to a fixed number, which changes when the rows are moved.
As this question have been answered on sitecore.stackexchange.com, I want to bring the answer here as well. Big credit to Richard Seal and Thomas D.
Thomas D:
You can try to open the standard values item with the Experience Editor and add the renderings you like.
Richard Seal:
This is an alternative to the method mentioned by Thomas D.
The Fortis solution uses the UID for the rendering attached to the placeholder key that you enter. You can get this by changing to Raw Values view and copying the xml out of the renderings or final renderings field.
Find the rendering that contains your placeholder. There will be an xml element like this:
<r id="{CA76EB6F-2934-4B8A-BB6A-508A8E44A7C5}"
ph="body"
uid="{0FD41EBD-43CF-4647-8A0F-F1F1D2E00CCD}" />
There may be other fields too. The 2 that are important are id, which is the item id of your rendering item and uid, this is the unique rendering id that is added to your placeholder key.
The key is built like this: string.Format("{0}_{1}", placeholderName, renderingId);
So if you have a placeholder key called title, the key for the above xml snippet would be: title_{0FD41EBD-43CF-4647-8A0F-F1F1D2E00CCD}
Set data source for a chuck item using small drop down box template in Sitecore
I couldn't see any data source field in this template, how I suppose to fill the drop down. I can add a single item by filling values in items fields
Small Drop Down Box template uses Items field so you tried correctly.
If you want it to add more than 1 item, you should separate them using pipe character |.
From what I know there is no way of using a datasource item for that template.
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.
Need help with a concept. Building a custom element that displays data from my database. Using a repeat template and it working great. The report is grouped and so each row in the report contains another level of data that is displayed once you drill into a row. So now I want to be able to "refresh" the report data to reflect sort or grouping changes. The report is based off an "indexing" array that points to the actual data displayed. I sort/group the data in the index array, and use this array as the array for the Template Repeat.
<div id="rptbody">
<template repeat="{{group in groups}}">
<pmg-group groupid={{group.id}} groupval={{group.groupval}} groupobj={{group.groupobj}}></pmg-group>
</template>
</div>
So in this example, the groups array is a list of keys to my data. In this example, the groups array is ordered properly so that [0] contains the first index to the data array, and [length-1] contains the last. I have a sort routine that changes the index value in groups, but it does not add or remove items from the groups array.
So my question is after my resort, how do I trigger the template to rescan the groups list? I have found that I can set groups = [], and then reload groups ( groups.push({idx} ) from my master index, and it will update the template, however that seems kind of wasteful to me.
Is there any way to trigger the template to refresh, or rescan the groups array and reorganize the DOM based on the changes in the values?
In the past I've gotten template repeats to refresh like this:
var template = document.querySelector('template'); // Use specific selector here
template.iterator_.updateIteratedValue(); // Force Polymer to refresh template
It's a hack, but it looks like it still works. Here's a jsbin.
Just stumbled on this and found out we have to use the .set method of the Polymer element data model. Not directly found any docs about this but this seems interesting https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#set-path. Would avoid those hacky things because they could change API over the time.