0

Is there anyway to make auto-save once I added a sublayout component?

I created one sublayout and if I add it on the page in page editor, it doesn't appear on that time. By saving the item, it appears on the page editor.

So, I'd like to make if sublayouts are added on the page, then make the page automatic save.

Is it possible?

===== Update =====

This is the end of CreateNewDatasource Method and it updates Rendering Layout field.

//set datasource, save and close
myItem.Editing.BeginEdit();
myDataSourceItem = myItem.Add(newName, template);
rd.Datasource = myDataSourceItem.ID.ToString();
myItem[Sitecore.FieldIDs.LayoutField] = ld.ToXml();
myItem.Editing.EndEdit();
myItem.Editing.AcceptChanges();

return myDataSourceItem;
Jay
  • 1,170
  • 1
  • 11
  • 34
  • 1
    The component should appear, is there any javascript on there, or does it need some javascript to act on it to appear? If so, Check your browser console window for any errors – jammykam Mar 13 '15 at 20:16
  • The reason is that the datasource is created from component. Once the sublayout is added on the page, the sublayout checks if there is any datasource information for the sublayout. If datasource is empty, create new item under the page item. Until I save the page, the new datasource has not been created. I think that's why the sublayout doesn't appear until I save. – Jay Mar 16 '15 at 13:45
  • I have updated the source code. It is the end of CreateNewDatasource Method. I updated layoutField and close the Edit mode. – Jay Mar 16 '15 at 14:01
  • Where are you running that code from? A specific event handler? Normally I just handle this by setting `Datasource Location` and `Datasource Template` on the sublayout item which forces a _Select Associated Content_ dialog, allowing you to create new content using that dialog: http://imgur.com/WCA1N3j http://imgur.com/4htB5v1 – jammykam Mar 16 '15 at 15:13
  • I'm running the code at sublayout's code file (sublayout.ascx.cs). CreatingNewItem method is from another class and sublayout.ascx.cs calls the class when the sublayout is embeded onto a page item. I have never seen what "Select Associated Content dialog" is and I don't know how it works. – Jay Mar 16 '15 at 18:05

2 Answers2

1

I'm not sure what the exact issue is with the way you have the control coded currently, I assume is to do with Sitecore control lifescycle so would need more in depth investigation. In any case, I suggest you re-think and implement using a more Sitecore friendly process.

Instead you should Prompt the User to Select/Create Datasource Item when inserting Rendering via Page Editor. The user can then either select an existing item or create a new one. The item will automatically be set as the datasource of your control and you will be able to immediately start editing in the Page Editor without having to save first.

jammykam
  • 16,940
  • 2
  • 36
  • 71
  • Thank you so much, jammykam. I will try to follow your direction! :) – Jay Mar 17 '15 at 11:40
  • jammy, if I create an item through a sublayout component, will the new item appear after saving the item? The sublayout is for sliderShow widget and it includes creating item if datasource field is empty in sublayout's datasource field. – Jay Mar 18 '15 at 14:21
  • It depends on your datasource template. Normally with a carousel you want to set the datasource to a parent folder and then display all children. So the Template (and item you would therefore create) would be a container folder of some sort. To create each slide, you would need to use Webedit/Custom Experience Button. – jammykam Mar 18 '15 at 23:41
  • Can't find a really good example but some useful info here: http://sirchicken.blogspot.co.uk/2015/02/the-rich-pageexperience-editor.html – jammykam Mar 18 '15 at 23:49
-1

It would be possible to make changes to the webedit.js file of sitecore but I would not recommend it because:

1) You will run into problems if you want to upgrade your solution to a newer version of sitecore later on.

2) The whole page will be saved everytime you add a new sublayout. The editor will not be able to discard his changes if he decides not to save the item after doing some other changes.

3) I also think that it is true what jammykam sayed in his comment. If the newly added sublayout will not appear on the page, there will be some javascript sideeffect caused by scripts on the page. To avoid this you could modify your sublayout or layout not to include custom javascript files when sitecore is in pageedit mode as a workaround and find out if this solves the problem.

DrDrakken
  • 37
  • 7