i want to do that because i need a second dato om make a sort on that overrules created date... so i was hoping i could fit umbraco to do i by default when creating a site (wich is a teaser....)
...well, makes more sense, but then I still wouldn't use the publish date for that, I'd add another date field on document type(s) and write a simple event handler that'll fill in that field for you.
Details on how to build an event handler can be found in the wiki starting here.
Ok, i created my handler in the app_code directory... And im thinking to use the "Document_AfterNew".... But how will i fetch my new "sortdate" date field so i can set datetime.now into it?
Ok, i think i got it, used the "beforepublish" instead because "afternew" did not have ref to the current document. Thanks for helping ;-)
Here is my code: publicclassSetBlogSortDate : umbraco.BusinessLogic.ApplicationBase { public SetBlogSortDae( { Document.BeforePublish += newDocument.PublishEventHandler(Document_BeforePublish); }
set the "Publish at" automatic
Is it possible to set the "Publish at" automatic to the same as "created date" when a new page is created?
why would you do that? you can publish document immediately after having created it
Cheers,
/Dirk
i want to do that because i need a second dato om make a sort on that overrules created date...
so i was hoping i could fit umbraco to do i by default when creating a site (wich is a teaser....)
...well, makes more sense, but then I still wouldn't use the publish date for that, I'd add another date field on document type(s) and write a simple event handler that'll fill in that field for you.
Details on how to build an event handler can be found in the wiki starting here.
Cheers,
/Dirk
Hi Dirk,
Finally i have time to respond now. Sorry for waiting.
Im brand new to Umbraco, so here is maybe a couple of stupid questions....
I have created a new "sortdate" date field on the "properties" tap.
1/
When writing a event handler class, does it have to be located a specific place in the solution?
2/
The new field value must only be set once when publishing the page the first time, how do i do that?
Ok, i created my handler in the app_code directory...
And im thinking to use the "Document_AfterNew"....
But how will i fetch my new "sortdate" date field so i can set datetime.now into it?
Ok, i think i got it, used the "beforepublish" instead because "afternew" did not have ref to the current document.
Thanks for helping ;-)
Here is my code:
public class SetBlogSortDate : umbraco.BusinessLogic.ApplicationBase
{
public SetBlogSortDae(
{
Document.BeforePublish += new Document.PublishEventHandler(Document_BeforePublish);
}
void Document_BeforePublish(Document sender, PublishEventArgs e)
{
if(sender.Template == 1185 && sender.getProperty("sortDate").Value == string.Empty)
{
sender.getProperty("sortDate").Value = DateTime.Now;
}
}
}
is working on a reply...