The only thing I would mention which I think someone else touched on is that the sender.Save(e.Entity); will actually fail when creating new nodes. The reason for this is the blank node does not yet have a name.
You can either set the name and the same will be ok.
Or like someone previously said just delete that line of code and don't run the save.
Dependents on what version ofUmbraco you are using there are some packages for handlingofstandardvalues on document types, I donĀ“t know if there are any package for this to version 7.
By here are some of the package that are available for previous versions of Umbraco
In case anybody else is curious, a coworker of mine created this plugin for Umbraco 7 that does pretty much what Andy said (side note: humorously, my coworker is also named Andy), but it bases the new content nodes on existing content nodes (i.e., you can edit the default content in Umbraco):
Hello everybody.I had a similar issue.I have tried this solution and it works for me for textstrings.
BUT, what if you want to do this in a dropdown list???How to set default value in this control?
How to set default values for properties when creating a new node from document type
Hello All,
How can I set a default value for my property so that when I create a new node/document from my document type, it auto populates the value.
For example:
Name: Page Title
Alias: pageTitle
Type: Textstring
How do I by default set the page title to untitled every time a new node/document of this document type is created.
Cheers,
Mark
You can look at events for this Mark. I've done something similar using an event handler class something like the following:
Seems
sender.Save(e.Entity);
will persist the documentFor those just looking for prepoluation of the form. leave that statement out...
Andy,
3+ yrs later and you still hit the mark!
Thank you for adding this as it helped me understand quite a few points I had slightly wrong!
h5yr!
Good to know if it works, but worth flagging that now, I believe these events have been obsoleted - see here.
So might not be around for the next major version and as those docs indicate may not work in all scenarios.
You might want to look at content templates now for this type of thing.
Andy
Andy,
Thanks again for this, I knew about those being obsoleted but at the moment the site is stuck on 7.5.11.
I'm in talks to update the whole process in the new year so we can use 7.7+ in new projects going forward.
Content templates are one of the main reasons for this, as well as all the other wonderfulness packed into the system now! :-D
Cheers for the heads up nonetheless!
Jon
Great. Thanks.
The only thing I would mention which I think someone else touched on is that the sender.Save(e.Entity); will actually fail when creating new nodes. The reason for this is the blank node does not yet have a name.
You can either set the name and the same will be ok.
Or like someone previously said just delete that line of code and don't run the save.
Hi Mark,
Dependents on what version of Umbraco you are using there are some packages for handling of standard values on document types, I donĀ“t know if there are any package for this to version 7.
By here are some of the package that are available for previous versions of Umbraco
Standard Values in Umbraco: http://our.umbraco.org/projects/developer-tools/standard-values-in-umbraco
Default Values for Umbraco: http://our.umbraco.org/projects/developer-tools/default-values-for-umbraco
Maybe this can be useful to you.
/Dennis
Hey Dennis, many thanks for your answer but Andy has hit the nail on the head as thats exactly what i was looking for. Works great!
In case anybody else is curious, a coworker of mine created this plugin for Umbraco 7 that does pretty much what Andy said (side note: humorously, my coworker is also named Andy), but it bases the new content nodes on existing content nodes (i.e., you can edit the default content in Umbraco):
https://our.umbraco.org/projects/backoffice-extensions/contenttemplates/
Hello everybody.I had a similar issue.I have tried this solution and it works for me for textstrings. BUT, what if you want to do this in a dropdown list???How to set default value in this control?
is working on a reply...