Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • olst 69 posts 88 karma points
    Feb 01, 2012 @ 13:35
    olst
    0

    Events: assign a property after document creation

    Hi.

    I want to assign a property called "pageBrowserTitle" the document name right after it is created.

    I think I should use the after_save event but how can I get the document name in this event ?

    something like :

    sender.getProperty("pageBrowserTitle").Value = sender.name;

  • Rodion Novoselov 694 posts 859 karma points
    Feb 01, 2012 @ 14:00
    Rodion Novoselov
    0

    Hi. It looks like what you want is already implemented in the "Standard values" package.

  • olst 69 posts 88 karma points
    Feb 01, 2012 @ 16:00
    olst
    0

    Thanks, Exactly what I needed !

  • olst 69 posts 88 karma points
    Feb 01, 2012 @ 18:02
    olst
    0

    I tried the package, but it isn't working as expected, so is there a way to do it with events nonetheless ? it really should be a simple task right ?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Feb 01, 2012 @ 18:25
    Jeroen Breuer
    0

    Hmm the package should work. If you want to do it with events you can do this:

    public class DigiApplicationBase : ApplicationBase
    {
        /// <summary>
        /// Set all the events which need to be handled. The constructor is called on application start.
        /// </summary>
        public DigiApplicationBase()
        {
            Document.New += new Document.NewEventHandler(Document_New);
        }
    
        #region Events
    
        /// <summary>
        /// This method get's called if a new document is created.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Document_New(Document sender, NewEventArgs e)
        {
            if (sender.getProperty("currentDate") != null)
            {
                //If the Document has a property with the name 'currentDate' set it to the current date.
                sender.getProperty("currentDate").Value = DateTime.Now;
            }
        }
    
        #endregion
    }

    Here you can find more info about events: http://www.richardsoeteman.net/2009/02/22/UmbracoV4EventsDemo.aspx

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Feb 01, 2012 @ 18:26
    Jeroen Breuer
    0

    And this one will work for what you need:

    if (sender.getProperty("pageBrowserTitle") != null)
    {
        //If the Document has a property with the name 'pageBrowserTitle' set it to the current name.
        //Normally we do this with the Standard Values package, but that won't work because of a bug: http://our.umbraco.org/projects/developer-tools/standard-values-in-umbraco/bug-reports/23581-Properties-on-inherited-tab-not-visible
        sender.getProperty("pageBrowserTitle").Value = sender.Text;
    }

    Jeroen

  • Rodion Novoselov 694 posts 859 karma points
    Feb 01, 2012 @ 18:34
    Rodion Novoselov
    0

    Yeah, of course it's possible - ultimately "Standard values" work on events anyway. I've done the things already by hand - below is a snippet:

    public class MyApp: ApplicationBase
    {
    public MyApp()
    {
                Document.New += Document_New;
    }

        void Document_New(Document sender, NewEventArgs e)
        {
            if (sender.ContentType.Alias.ToUpper() == "TEXTPAGE")
            {
                sender.getProperty("title").Value = sender.Text;
            }
        }
    }

     

  • Rodion Novoselov 694 posts 859 karma points
    Feb 01, 2012 @ 18:47
    Rodion Novoselov
    0

    I still think that probably it would be better worth to invest some efforts to fixing the bug once than to create new and new custom solutions for the problem on end - it's opensource anyway...

Please Sign in or register to post replies

Write your reply to:

Draft