A context is a hidden data source Backdrop uses to construct a given page.
The Layout system often requires a node or a user or other data source to extract the information visible on a particular page. A Context is Backdrop's name for this data source.
Blocks can have a required context. This means that if the context is not available, Backdrop will not try to display the block. A block that displays information about a the author of a Post, for example, would not display if you were not on a page that had anything to do with a Post. In this case, the content (or Node) is the required context.
Blocks without a satisfied context will not appear in the list of blocks that are available on a layout, so you can’t add broken blocks by mistake.
Backdrop has a great feature which allows individual fields from a node to be displayed as separate blocks. These blocks are then available in the Layout UI's "Add block" list as Field blocks. You could identify Field blocks in the block list by their naming format which is the word "Field:" followed by the field name and then the field machine name in brackets, such as "Field: Image (field_image)". But if you went into the Default layout you would find no Field Blocks listed in the block list. Why? Because Field blocks have declared that for them to work, the page must be the display page of a node or some other entity. Since the default layout can be used on any page, that page may not be an entity page, therefore Backdrop hides Field Blocks from the default layout's block list.
If you want to use Field blocks then, you need to create a layout which provides an entity to Field Blocks. Qualifying layouts would be ones where the "path" of the layout is of the format '<entity>/%' for example 'node/%' or 'user/%'. This tells Layouts that this layout must be ready to deliver an entity context to its blocks, where the entity type is the first part of the path (eg 'node') and the entity ID is the second part of the path.
So for a layout with the path 'node/%', visiting the "Add block" page would show those Field Blocks which have required the 'node' entity, such as "Field: Image (field_image)". If this block is placed in the layout sidebar and the layout saved, visiting a path such as 'node/55' would allow this image to be displayed (providing as well an image had actually been uploaded in the Image field, of course) in the sidebar as its own block.
Example: Adding an image Field Block
- Create a "Post" type node, give it any name, and type some body content
- In the image field, upload an image and save the node
- Be sure to recall the new node’s URL (in the address bar)
- Now create a new layout by visiting '/admin/structure/layouts' and click "Add layout"
- Add a name for the layout and choose any template with a sidebar (any template will do but we like a sidebar for this demo)
- For the path, type in 'node/%' without the quotes
- Click "Save layout" to be redirected to the blocks page
- Now in the sidebar region, click the "Add block" link and search for the image block "Field: Image (field_image)" and insert it into the layout by clicking the "Add block" button. More information about configuring Field blocks is available in the “Configuring blocks: examples” tutorial.
- Click "Save layout"
Visit the URL of the node you create in the first step to see that the image is now in the sidebar as its own block