Setting default value to Name of page?

Dylan McCurry
Member since: 2018


I am trying to set one of my fields to default to the name of the page item created.  The field is for breadcrumb title, so it logically makes sense to default this to the page name.

I've tried overriding SetDefaultValues on my Page model, but it seems that this function is called before the user is prompted for the page name.

Is this possible in episerver?

#194810 Jul 03, 2018 20:45
  • alf.nilsson
    Member since: 2008

    Previously to do this I have needed to hook up on the ContentCreated event (or if it was ContentCreating, unfortunately I don't remember).

    Unless in your view model you create a fallback so if the Breadcrumb does not have a value, use the Page Name instead.

    #194811 Jul 03, 2018 22:41
  • Marija Jemuovic
    Member since: 2010

    Hey, Dylan,

    Given that you already have the value for PageName that breadcrumb name should fallback too, I wouldn't write the same value to the database, but rather do what Alf proposed. When getting the breadcrumb, have something like BreadcrumbName ?? PageName.

    If it was more complex than that, if you had some difficult logic to choose the BreadcrumbName, Creating or Publishing would do the work (since in these events, the content is writable). However, "BreadcrumbName ?? PageName" will hardly give you any performance reason to do that.


    #194916 Jul 08, 2018 15:49
  • Dylan McCurry
    Member since: 2018

    Thanks!  This makes sense!

    #194927 Jul 09, 2018 14:49