Layout Handles
The Observer/LayoutLoadBefore.php observer dynamically adds a layout handle to every blog page request. These handles allow targeted layout customization per page type.
Layout Handles
| Handle | Page | Layout File |
|---|---|---|
ocmlabs_ | Blog post listing | view/ |
ocmlabs_ | Single post page | view/ |
ocmlabs_ | Category archive | view/ |
ocmlabs_ | Tag archive | view/ |
ocmlabs_ | Author archive | view/ |
ocmlabs_ | Search results | view/ |
Additional Handles
| Handle | Added when | Layout File |
|---|---|---|
ocmlabs_ | Included by the blog home, post, category, tag and search handles. Adds the WordPress menu block to sidebar.main | view/ |
ocmlabs_ | Blog home, first page only, when Blog Home Page Content is a Front Page option and a front page is set in WordPress. Adds the wp.blog.front.page block | view/ |
ocmlabs_ | As above, with WordPress Front Page Only. Removes the wp.blog.post.list block | view/ |
These were added in 2.1.0. The blog controller adds the front page handles before the layout loads.
Page Layout
Since 2.1.0, the page layout (2columns-left, 2columns-right or 1column) comes from the Page Layout settings. The observer sets it on the page config, which takes precedence over the layout attribute in the module’s layout files and in your theme’s.
How Handles Are Added
The handle name is constructed as ocmlabs_{controller}_{action}:
- Controller name: the request controller name (set by the Router based on the URL pattern matched)
- Action: the controller action name (
index,view,results)
For the post view controller, the handle is ocmlabs_post_view. For the blog index controller, it is ocmlabs_blog_index.
Since 2.0.5, Magento also adds its own default handle for each blog page, built from the wordpress route name, for example wordpress_blog_index and wordpress_post_view. The module ships no layout files for these. Use the ocmlabs_* handles for your customizations.
Using Layout Handles in Your Theme
To add content to the blog listing page sidebar in your theme:
File: app/design/frontend/Your/Theme/OCMLabs_WordPressIntegration/layout/ocmlabs_blog_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="sidebar.main">
<block class="OCMLabs\WordPressIntegration\Block\Sidebar\Categories"
name="blog.sidebar.categories"
template="OCMLabs_WordPressIntegration::sidebar/categories.phtml"
after="-"/>
</referenceContainer>
</body>
</page> To apply changes to all blog page types at once, use a layout update that references all six handles.
See also
Related pages
- Templates and ViewModels
- Sidebar blocks you can attach to these handles
- Adding a new blog page type