Copied to clipboard

Flag this post as spam?

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


  • Amit 10 posts 81 karma points
    Apr 23, 2017 @ 09:22
    Amit
    0

    Custom code for document type

    Hello all, I'm relatively new to Umbraco and after going through all of the tutorials I managed to get my hands on, I still couldn't find an answer to my question -

    Is it possible in Umbraco to define a "constructor" for a document type, Regardless of its hierarchical position as a page of itself, or as a nested content in another document type.

    The idea I'm pursuing is to define a custom code section to initialize things that are external to Umbraco, to allow my content editors to use this document type on any other document type (as a child) and for the custom code for my first document type (the nested one) to be initialized accordingly.

    I'm aware of route hijacking and I am currently using it, but with that approach I'm bound to define a custom controller per each new document type that is intended to use my nested document type, i'm wondering if there is a way to achieve what I'm after.. (sort of a constructor\event handler for the child document type)

    Thanks in advance to all potential helpers :)

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    May 19, 2017 @ 21:55
    Alex Skrypnyk
    0

    Hi Amit

    Also you can use ContentService events - https://our.umbraco.org/documentation/reference/events/contentservice-events

    Split code for each document type and call some constructor per document type if it's the case.

    Alex

  • Amit 10 posts 81 karma points
    May 21, 2017 @ 05:10
    Amit
    0

    Hey Alex, thanks for replying.

    The thing is that there are no "on load" event for documents, only published and created.

    I wish to run a custom code for each document type, regardless of said document type being a page on its own or as children of another document type...

    it seems that this is impossible, thus i cannot completely encapsulate a document type's custom logic inside it.

    I must take into account WHERE is that document being used (and deal with the custom logic of it in that place i.e. a parent document..)

    Am I correct or am i missing something?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies