Copied to clipboard

Flag this post as spam?

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


  • Allan Svelmøe Hansen 25 posts 136 karma points
    Aug 23, 2018 @ 09:09
    Allan Svelmøe Hansen
    0

    Overwrite/Dynamic Composite Tab Names

    Hi.

    I have a composite I would like to use in multiple document types, however, I would like the tab name to be different depending on which document type I'm using it on.

    In this specific example, I'm using a "background" composite in some types where I'd like it to be named something like "Background Settings". However I would also like to use it on another document types where it could be named for example: "Header Background"

    So basically - changing the tab's display name for the composite depending on it's inclusion in different document types/locations without needing to make duplicate composites.

    Is this possible somehow?

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Aug 27, 2018 @ 10:24
    Marc Goodson
    101

    Hi Allan

    No this isn't specifically possible 'easily'

    The way the concept of properties in Umbraco has evolved over the years, and the corresponding database storage, means a particular property in a document type is very tied to the 'tab' it has been added to.

    The changes required to make possible what you describe, (though very intuitively how you might expect it to work) would be prohibitively big...

    Anyway more pragmatically some options:

    1) If you called your tab just 'Background' then in both scenarios it would probably make sense to the editor!

    2) Duplicate the composition, really theoretically you could argue although in the two scenarios you currently require the same 'properties' - that perhaps at a future date, the header background scenario might require an additional property, that the other scenario doesn't require, so they 'should be different' compositions (their properties can have the same name - and you can use the copy function so you don't have to retype them!), essentially the idea that the tabs should have different titles for the editors sort of implies they are 'different' things albeit 'really similar' :-P

    3) Finally, if you really must... you can programmatically change the title of the tab before it is rendered to the editor in the two different circumstances, based on the alias of the document type - you achieve this by handling the EditorModelEventManager SendingContentModel event, finding the Tab, and updating it's Label...

    https://our.umbraco.com/documentation/reference/events/EditorModel-Events

    eg Create a class that implements IApplicationEventHander, and wire up to the SendingContentModel event:

      public class UmbracoBooter : IApplicationEventHandler
        {
            public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
    
            }
    
            public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                EditorModelEventManager.SendingContentModel += EditorModelEventManager_SendingContentModel;
            }
    
            private void EditorModelEventManager_SendingContentModel(System.Web.Http.Filters.HttpActionExecutedContext sender, EditorModelEventArgs<Models.ContentEditing.ContentItemDisplay> e)
            {
                if (e.Model.ContentTypeAlias == "AliasOfDocTypeRequiringHeaderBackgroundTab")
                {
                    e.Model.Tabs.FirstOrDefault(f => f.Label == "Background").Label = "Header Background";
                }
            }
    
            public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
    
            }
        }
    
  • Allan Svelmøe Hansen 25 posts 136 karma points
    Aug 28, 2018 @ 06:01
    Allan Svelmøe Hansen
    0

    Thanks for the comprehensive answer - I was "afraid" it was like that - but I had hoped the display name was merely a text value/translation in the association between the composite and the "final" document type as it could be seperated from the system name. :)

    Anyway - thanks once again, I'm going the more 'generic' route in the naming, as the issue is not 'too critical' but merely a UX issue. :)

Please Sign in or register to post replies

Write your reply to:

Draft