Copied to clipboard

Flag this post as spam?

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


  • Danine Noble 75 posts 330 karma points
    Dec 01, 2023 @ 19:07
    Danine Noble
    0

    Dynamically prefill a field upon content creation

    Hullo all, I'm curious...

    Is there currently any way to use Content Templates to also prefill a field value dynamically? Just for super common things like auto-filling a 'Page Title' field with whatever the name of the content item was when the author creates it for example.

    From a quick look around I can only find things about hard setting text values and nothing along the lines of reserved tokens like $name or something.

    Edit: Though, having played around more with Content Templates I realized the content creation is after authors edit & hit save ^^; So to accomplish this (if possible at all) it'd have to auto save or intercept and ask for info first if it was something like prefilling a name. *thinks

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Dec 09, 2023 @ 23:54
    Marc Goodson
    0

    Hi Danine

    Normally I'd say have a look at the SendingContentNotification

    https://docs.umbraco.com/umbraco-cms/reference/notifications/editormodel-notifications

    This fires just before a page is presented to an editor and allows you to manipulate property values etc...

    But, actually what you are describing is setting the Page Title property based on what the editor types into the Name field... So the page will have already displayed.

    Years and years ago, I created a custom property editor tgat would sync with the name field...

    https://github.com/marcemarc/tooorangey.NameSync/tree/master/tooorangey.NameSync

    So as the editor typed into name field the same would appear in page title... Or editor could choose to usync them and have something different..

    It probably won't work in the latest umbraco but provides a gist...

    What I tend to do with sites now though is have a convention where

    Name = name of page in Navigation menus

    Page Title = main H1 of the page

    And then I put a note under Page Title that says if left blank this will default to the Name...

    And then in the code check if page title has value and if not render the name instead...

    Regards

    Marc

  • Danine Noble 75 posts 330 karma points
    Dec 11, 2023 @ 17:34
    Danine Noble
    0

    Yeah that's just a field fallback set, but thank you!

    What I was hoping to discover was a way to help speed up the creation of new pages for authors by having dynamic prefills on creation. Exactly what the Content Template feature seems to be for, but the problem with it OOTB is it's all hard-set values. It doesn't allow for, say, a pattern. (Unless I'm totally missing something! Which would be what I'm looking for ;D Content templates still obviously handy for including default components for a page for example)

    Patterns being things such as a Page Title field typically containing the name of the content item but often having additional words, prefilling it with the name is just a small nicety for authors; or SEO fields from a package having the content item's name + some suffix (ie: Name | Site); or news/blog style pages that will always have a 'publish' date field being automatically set to the day after it was initially created; etc etc. But all 100% changeable as normal (not forcibly synced forever) by authors if the content needs something different.

    Stuff like that as just generic examples I can think of having been used on projects in other systems.


    Would it be possible to make something with a flow like:

    1. Authors go to Create a new content item, selecting a Content Template for the doc type.
    2. They are prompted for initial information (ie: name for page)
    3. Page is immediately created/saved in the content tree, initialized with prefill values based on input. No further forced syncing of values.
  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Dec 11, 2023 @ 22:00
    Marc Goodson
    100

    Hi Danine

    I do like the having placeholders in the content template idea, but the fundamental issue, as you point out yourself, is that when an editor creates a new content item, either afresh or from a content template blueprint they don't specify a name... The empty page or the page populated with the content template info, is there in front of them before they type in the name!

    There are notifications that fire before this happens in the SendingContentNotification so you can manipulate content before it is displayed for editing... And then a ContentSavingNotification fires when a page is saving so you can change property values after they have been edited...

    So a clunky version of what you want could be created. If after creating a new page from scratch or from a Content Template, the editor adds the Name of the page and immediately presses save... Then you could in your saving event, take the name and replace the page title if its empty, and run whatever logic you like to replace {placeholders} you put in the Content Template.. And you could use the Sending Content notification before this to set today's date for an article etc...

    But it would be super clunky... As an editor I'd think it odd but if it saved me loads of work I might get over it...

    Ironically in Umbraco 6...when you created a new page you had to specify the name of the page in the dialog, and the content item was saved to the database before you got to enter the rest of the page properties... Which would make this less clunky...

    ... Which got me thinking... And you ask if it is possible... And it sort of is... But it would be a bit of an effort...

    Basically before every content item is rendered in the content tree on the left hand side, there is a MenuRenderingNotification you can handle...

    https://docs.umbraco.com/umbraco-cms/extending/section-trees/trees#menurenderingnotification

    And so you could remove the Create menu item from each node and replace it with your own 'Super Create' menu item which can be configured to call your own angularJS view... Now initially you want the editor to have the same choice of doc type or content template as the Umbraco Create menu, so you would copy those views and angularJS controllers from the core... But difference being when one is selected, instead of redirecting to the New page type you would present your own custom view with a text box for the name of the new page, when the create button is clicked the custom angular JS controller for view would take the name, Id of page under which the new page will sit along with the selected content type and send it to a custom UmbracoApiController routed for the backoffice, here you'd use the Contentservice to create and save the page of the new type... And this will create a new content I'd, which you return back to the angular JS controller that then constructs the backoffice url to edit the item based on new Id and redirects the editor there... If you haven't done all your custom schnizzel when you created the page you could use the sendingcontent notification to set the properties now that you have the name!

    So yeah it's possible! - but you'd probably want a big trade off for speeding up editing and a big hug from the editorial team to tackle it!

    Regards

    Marc

  • Danine Noble 75 posts 330 karma points
    Dec 13, 2023 @ 18:56
    Danine Noble
    0

    Definitely would need a big hug ;D

    This is great detail, thank you so much for the insight! A thing to ponder and play with perhaps. The current Content Templates work for like 90% of most useful preset cases ^^

Please Sign in or register to post replies

Write your reply to:

Draft