This is my first attempt at creating a Marionette app, and I am interested in implementing the Marionette UI structure.
From what I understand,
- A Region corresponds to an existing, single DOM node (such as a div or a span) and can hold Views, including those provided by Marionette
- A Layout acts as both a View and a container for Regions, defining how these regions will be arranged; it can also be rendered into a Region
It seems that the hierarchy should follow this pattern:
- Root (region) [possibly multiple]
-- Layout A
--- Inner Region A1
--- Inner Region A2
-- Layout B
--- Inner Region B1
--- Inner Region B2
-- View C
--- possibly some subviews?
If I have misunderstood anything, please correct me.
In my application, there are navigation and content sections in the UI. When the script is loaded, it might be injected into a page with an existing #region-navigation div for custom styling, or it could be added to a page without this node. If the navigation node exists, no need to render it, but we still need to access and manipulate it. If it does not exist, we must render it.
My question is: what is the best way to approach this using Marionette? I have a plan in mind, but I want to avoid unnecessary complications.
I propose creating a RootRegion with a selector (defaulting to body) that doesn't exist initially.
I would have two AppLayouts: InjectedAppLayout with only a Content region, and ManagedAppLayout which replaces the body contents.
Based on script data attributes and/or jQuery checks, I would choose the appropriate Layout.
In both cases, there would be a HeaderRegion and a ContentRegion. For InjectedAppLayout, HeaderRegion remains outside while ManagedAppLayout includes both. Depending on the management method, I may use ExternalHeaderRegion and InternalHeaderRegion or implement conditionals.
Despite seeming inefficient, I haven't come across examples of how people handle this scenario.
Regarding InjectedAppLayout, I'm concerned about the size of the div containing the ContentLayout despite wider screens. My bootstrap styles and media queries rely on max-width values - will these apply to the injected layout's div?