foundation-layout.foundationlayout.loadlayout
Home > @genesislcap/foundation-layout > FoundationLayout > loadLayout
FoundationLayout.loadLayout() method
Restores a layout described in the config from getLayout()
Signature:
loadLayout(layout: SerialisedLayout, handleMissingItem?: 'placeholder' | 'error', disableCache?: boolean): void;
Parameters
Parameter | Type | Description |
---|---|---|
layout | SerialisedLayout | any version of SerialisedLayout object describing the layout |
handleMissingItem | 'placeholder' | 'error' | (Optional) what to do if the layout contains items that are not currently registered with the layout system. Defaults to 'error' which will throw an error. If set to 'placeholder' then any missing items will be replaced with a placeholder element. You can control the text of the placeholder element with FoundationLayout.missingItemPlaceholder. |
disableCache | boolean | (Optional) if set to true then the layout will give you a new instance of every item, even if it has a currently cached item to use. Using this will not stop you from saving and loading state via the LayoutComponentWithState interface. Defaults to false. |
Returns:
void
Exceptions
LayoutUsageError if you attempt to load a layout with registered items that are not currently registered with the layout system, and handleMissingItem is set to 'error' (default).
various errors if the layout string is malformed and cannot be parsed
Remarks
In order to restore a layout you must have registered all of the required panes with the layout system before restoring it. If you are just setting the layout using the declarative API then all of the same components will be registered. If you have added any elements using FoundationLayout.registerItem() then you must ensure all of the same items have been added again. To make tracking what items are registered easier it is recommended in this case you explicitly name your registrations using the id
parameter available on the RegisteredElementConfig and foundation-layout-item
APIs. You can use FoundationLayout.layoutRequiredRegistrations() to check which items are registered in a current layout in order to dynamically add any missing items before you can restore the layout