Du viser støtteinnhold for versjon:
- 6.4
- 6.3
- Eldre versjoner
Responsive Layout is a mechanism for realizing responsive web design. This allows the user to create web pages that have a layout and dimensions dependent on the devices their users use.
Merk:
This can be compared with the Mobile Web mechanisms, which use adaptive web design (primarily for the classic UI).
AEM realizes responsive layout for your pages using a combination of mechanisms:
- Layout Container component
This component provides a grid-paragraph system to allow you to add and position components within a responsive grid. It can be used as the default parsys for your page and/or made available to authors in the component browser.
- The default Layout Container component is defined under:
/libs/wcm/foundation/components/responsivegrid - You can define layout containers:
- As a component that the user can add to a page.
- As the default parsys for the page.
- Both.
You can have the layout container as standard for the page, while allowing the user to add further layout containers within this; for example, to achieve column control.
- The default Layout Container component is defined under:
- Layout Mode
Once the layout container is positioned on your page you can use the Layout mode to position content within the responsive grid. - Emulator
This allows you to create and edit responsive websites that rearrange the layout according to device/window size by resizing components interactively. The user can then see how the content will be rendered using the Emulator.
Forsiktig!
Although the Layout Container component is available in the classic UI, its full functionality is only available in the touch-enabled UI.
With these responsive grid mechanisms you can:
- Use breakpoints (that indicate device grouping) to define differing content behavior based on device layout.
- Hide components based on device group (define on which breakpoint a component will be hidden).
- Use horizontal snap to grid (place components into the grid, resize as required, define when they should collapse/reflow to be side-by-side or above/below).
- Realize column control.
Merk:
In an out-of-the-box installation, responsive layout has been configured for the We.Retail reference site. You must still activate the Layout Container component for other pages.
To enable the emulator to support your pages, you must register your page components. See Registering Page Components for Simulation.
To specify the device groups that appear in the Devices list of the emulator see Specifying the Device Groups.
To include the dmulator you need to link your site to the device groups. See Adding the Devices List (for both the classic and touch-optimized UI).
- Are used in responsive design.
- Can be defined:
- On the page template, from where the settings will be copied to any pages created with that template.
- On the page node, from where the settings will be inherited by any child pages.
- On the page template, from where the settings will be copied to any pages created with that template.
- Define a title and a width:
- The title describes the generic device grouping, with orientation if required; for example phone, tablet, tabletlandscape.
- The width defines the maximum width in pixels for that generic device grouping. For example, if the breakpoint phone has a width of 768 then that it the maximum width of the layout used for a phone device.
- Are visible as markers at the top of the page editor when you are using the emulator.
- Are inherited from the parent node hierarchy and can be overridden at will.
- There is a default (out-of-the-box) breakpoint which covers everything above the last configured breakpoint.
Merk:
If you are setting up a new project:
- you need to add breakpoints to the templates.
If you are migrating an existing project (with existing content) you need to:
- add breakpoints to the templates
- add the same breakpoints to the existing pages
As inheritance is in operation you can limit this to the root page of your content.
Breakpoints are located inside the <jar:content> section of the .context.html under the appropriate template (or content) folder.
An example definition:
<cq:responsive jcr:primaryType="nt:unstructured"> <breakpoints jcr:primaryType="nt:unstructured"> <phone jcr:primaryType="nt:unstructured" title="{String}Phone" width="{Decimal}768"/> <tablet jcr:primaryType="nt:unstructured" title="{String}Tablet" width="{Decimal}1200"/> </breakpoints> </cq:responsive>
Merk:
This is only needed if the page component is not based on the foundation page component.
Copy the following cq:infoProviders node structure into your parent page component:
/libs/foundation/components/page/cq:infoProviders/responsive
To set the main parsys of your page to be a layout container you need to define the parsys as:
wcm/foundation/components/responsivegrid
In either the:
- Page component
- Page template (for future use)
The following two examples illustrate the definition:
AEM uses LESS to generate parts of the necessary CSS, these need to be included for your projects.
You will also need to create a client library to provide additional configuration and function calls. The following LESS extract is an example of the minimum you need to add to your project:
@import (once) "/etc/clientlibs/wcm/foundation/grid/grid_base.less"; /* maximum amount of grid cells to be provided */ @max_col: 12; /* default breakpoint */ .aem-Grid { .generate-grid(default, @max_col); } /* phone breakpoint */ @media (max-width: 768px) { .aem-Grid { .generate-grid(phone, @max_col); } } /* tablet breakpoint */ @media (min-width: 769px) and (max-width: 1200px) { .aem-Grid { .generate-grid(tablet, @max_col); } }
Components held within a responsive container will be resized (together with their respective HTML DOM elements) according to the responsive grid size. Therefore, in these circumstances, it is recommended to avoid (or update) definitions of fixed width (contained) DOM elements.
For example:
- Before:
- width=100px
- After:
- max-width=100px
Any resizing of a component within the grid will trigger the following listeners as appropriate:
- beforeedit
- beforechildedit
- afteredit
- afterchildedit
To properly resize and update the content of an adaptive image included in a responsive grid, you need to add an afterEdit set to REFRESH_PAGE listener into the EditConfig file of every contained component.
For example:
<cq:listeners jcr:primaryType="cq:EditListenersConfig" afteredit="REFRESH_PAGE" />
The adaptive image mechanism is made available via a script that controls selection of the correct image for the current size of the window. It activates after the DOM is ready or when receiving a dedicated event. Currently the page must be refreshed to properly reflect the result of the user's action.
Forsiktig!
Custom stylesheet clientlibs must be loaded as part of the header for them to work properly on author as well as publish.
To allow authors to add further responsive grids to the content pages you need to enable the Layout Container component for your page. You can do this using either:
-
Use Design mode to activate the Layer Container component for a page.
-
You can configure the number of columns available for each specific instance of layout container.
To do this, use Design mode, then open the design dialog for the required container. Here you can specific how many columns will be available for positioning and sizing. The default is 12.
-